結果
問題 | No.1 道のショートカット |
ユーザー | femto |
提出日時 | 2015-03-30 21:43:45 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,644 bytes |
コンパイル時間 | 809 ms |
コンパイル使用メモリ | 115,108 KB |
実行使用メモリ | 30,060 KB |
最終ジャッジ日時 | 2024-07-08 03:50:33 |
合計ジャッジ時間 | 3,029 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
27,368 KB |
testcase_01 | AC | 27 ms
25,324 KB |
testcase_02 | AC | 26 ms
27,240 KB |
testcase_03 | AC | 27 ms
27,492 KB |
testcase_04 | AC | 26 ms
25,388 KB |
testcase_05 | AC | 25 ms
25,456 KB |
testcase_06 | AC | 26 ms
25,132 KB |
testcase_07 | AC | 25 ms
25,260 KB |
testcase_08 | AC | 30 ms
27,788 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 26 ms
25,388 KB |
testcase_16 | AC | 30 ms
27,556 KB |
testcase_17 | AC | 24 ms
23,348 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 33 ms
27,880 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 26 ms
27,460 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 31 ms
28,008 KB |
testcase_32 | AC | 33 ms
26,092 KB |
testcase_33 | AC | 31 ms
25,840 KB |
testcase_34 | WA | - |
testcase_35 | AC | 29 ms
25,740 KB |
testcase_36 | AC | 30 ms
25,648 KB |
testcase_37 | AC | 29 ms
27,640 KB |
testcase_38 | AC | 26 ms
27,184 KB |
testcase_39 | AC | 29 ms
27,560 KB |
testcase_40 | AC | 28 ms
25,580 KB |
testcase_41 | AC | 28 ms
25,448 KB |
testcase_42 | AC | 25 ms
25,644 KB |
testcase_43 | AC | 25 ms
27,244 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.Linq; using Enu = System.Linq.Enumerable; class Solution { public const int INF = (int)1e9; int N, C, V; int[] S, T, Y, M; void calc() { N = ri(); C = ri(); V = ri(); S = ria(V); T = ria(V); Y = ria(V); M = ria(V); var dijkstra = new Algorithm.Dijkstra(N, C); for (int i = 0; i < V; i++) { dijkstra.addDirEdge(S[i], T[i], Y[i], M[i]); } dijkstra.calcShortestPath(1); int ans = INF; for (int c = 0; c <= C; c++) { ans = Math.Min(ans, dijkstra.d[N, c]); } Console.WriteLine(ans != INF ? ans : -1); } static void Main(string[] args) { new Solution().calc(); } #region static int ri() { return int.Parse(Console.ReadLine()); } static int[] ria(int n) { if (n <= 0) { Console.ReadLine(); return new int[0]; } else return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static void rio(out int p1) { p1 = ri(); } static void rio(out int p1, out int p2) { var r = ria(2); p1 = r[0]; p2 = r[1]; } static void rio(out int p1, out int p2, out int p3) { var r = ria(3); p1 = r[0]; p2 = r[1]; p3 = r[2]; } static void rio(out int p1, out int p2, out int p3, out int p4) { var r = ria(4); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; } static void rio(out int p1, out int p2, out int p3, out int p4, out int p5) { var r = ria(5); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; p5 = r[4]; } static long rl() { return long.Parse(Console.ReadLine()); } static long[] rla(int n) { if (n <= 0) { Console.ReadLine(); return new long[0]; } else return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static void rlo(out long p1) { p1 = rl(); } static void rlo(out long p1, out long p2) { var r = rla(2); p1 = r[0]; p2 = r[1]; } static void rlo(out long p1, out long p2, out long p3) { var r = rla(3); p1 = r[0]; p2 = r[1]; p3 = r[2]; } static void rlo(out long p1, out long p2, out long p3, out long p4) { var r = rla(4); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; } static void rlo(out long p1, out long p2, out long p3, out long p4, out long p5) { var r = rla(5); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; p5 = r[4]; } static double rd() { return double.Parse(Console.ReadLine()); } static double[] rda(int n) { if (n <= 0) { Console.ReadLine(); return new double[0]; } else return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static void rdo(out double p1) { p1 = rd(); } static void rdo(out double p1, out double p2) { var r = rda(2); p1 = r[0]; p2 = r[1]; } static void rdo(out double p1, out double p2, out double p3) { var r = rda(3); p1 = r[0]; p2 = r[1]; p3 = r[2]; } static void rdo(out double p1, out double p2, out double p3, out double p4) { var r = rda(4); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; } static void rdo(out double p1, out double p2, out double p3, out double p4, out double p5) { var r = rda(5); p1 = r[0]; p2 = r[1]; p3 = r[2]; p4 = r[3]; p5 = r[4]; } static void swap<T>(ref T x, ref T y) { T temp = x; x = y; y = temp; } static void wa1<T>(T[] a) { Console.WriteLine(string.Join(" ", a)); } static void wa2<T>(T[,] a) { for (int i = 0; i < a.GetLength(0); i++) { for (int j = 0; j < a.GetLength(1); j++) Console.Write(a[i, j] + " "); Console.WriteLine(); } } #endregion } namespace Algorithm { using T = System.Int32; // require PriorityQueue public class Dijkstra { public const T INF = (T)1e9; public int maxCost; private class edge { public int from, to; public T cost, time; public edge(int from, int to, T cost, T time) { this.from = from; this.to = to; this.cost = cost; this.time = time; } } private int vnum; private List<edge>[] edgelists; public T[,] d; private PriorityQueue<Tuple<T, T, int>> que; // Item1:コスト, Item2:時間, Item3:頂点番号 public Dijkstra(int vnum, int maxCost) { this.vnum = vnum; this.maxCost = maxCost; edgelists = new List<edge>[vnum + 1]; for (int i = 0; i < edgelists.Length; i++) edgelists[i] = new List<edge>(); d = new T[vnum + 1, maxCost + 1]; } public void addDirEdge(int v1, int v2, T cost, T time) { edgelists[v1].Add(new edge(v1, v2, cost, time)); } public void addUnDirEdge(int v1, int v2, T cost, T time) { addDirEdge(v1, v2, cost, time); addDirEdge(v2, v1, cost, time); } public void calcShortestPath(int s) { for (int i = 0; i <= vnum; i++) { for (int j = 0; j <= maxCost; j++) { d[i, j] = INF; } } que = new PriorityQueue<Tuple<T, T, int>>((t1, t2) => t2.Item2.CompareTo(t1.Item2)); d[s, 0] = 0; que.Push(new Tuple<T, T, int>(0, 0, s)); while (que.Count() != 0) { var t = que.Pop(); int v = t.Item3; if (d[v, t.Item1] < t.Item1) continue; foreach (var e in edgelists[v]) { int nextCost = e.cost + t.Item1; if (nextCost <= maxCost && d[e.to, nextCost] > d[v, t.Item1] + e.time) { d[e.to, nextCost] = d[v, t.Item1] + e.time; que.Push(new Tuple<T, T, int>(nextCost, d[e.to, nextCost], e.to)); } } } } } public class PriorityQueue<T> { private List<T> buffer; private Comparison<T> comp; // 昇順 // (e1, e2) => e2.CompareTo(e1) // 降順 // (e1, e2) => e1.CompareTo(e2) public PriorityQueue(Comparison<T> comp) { buffer = new List<T>(); this.comp = comp; } public PriorityQueue(Comparison<T> comp, IEnumerable<T> data) : this(comp) { foreach (T e in data) Push(e); } public void Push(T elem) { PushHeap(this.buffer, elem); } public T Pop() { return PopHeap(this.buffer); } public int Count() { return buffer.Count; } public T Top() { return buffer[0]; } private void PushHeap(List<T> array, T elem) { int n = array.Count; array.Add(elem); while (n != 0) { int i = (n - 1) / 2; // 親と値を入れ替え if (comp(array[n], array[i]) > 0) { T tmp = array[n]; array[n] = array[i]; array[i] = tmp; } n = i; } } private T PopHeap(List<T> array) { int n = array.Count - 1; T returnelem = array[0]; array[0] = array[n]; array.RemoveAt(n); for (int i = 0, j; (j = 2 * i + 1) < n; ) { // 値の大きい方の子を選ぶ if ((j != n - 1) && (comp(array[j], array[j + 1]) < 0)) j++; // 子と値を入れ替え if (comp(array[i], array[j]) < 0) { T tmp = array[j]; array[j] = array[i]; array[i] = tmp; } i = j; } return returnelem; } } }