結果
問題 | No.2739 Time is money |
ユーザー | tenten |
提出日時 | 2024-08-02 17:03:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,153 ms / 2,000 ms |
コード長 | 2,527 bytes |
コンパイル時間 | 2,341 ms |
コンパイル使用メモリ | 79,724 KB |
実行使用メモリ | 97,316 KB |
最終ジャッジ日時 | 2024-08-02 17:03:32 |
合計ジャッジ時間 | 22,096 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
50,400 KB |
testcase_01 | AC | 48 ms
50,508 KB |
testcase_02 | AC | 518 ms
75,732 KB |
testcase_03 | AC | 1,024 ms
88,368 KB |
testcase_04 | AC | 574 ms
75,432 KB |
testcase_05 | AC | 779 ms
75,644 KB |
testcase_06 | AC | 884 ms
79,400 KB |
testcase_07 | AC | 1,087 ms
97,316 KB |
testcase_08 | AC | 1,048 ms
97,116 KB |
testcase_09 | AC | 1,040 ms
97,252 KB |
testcase_10 | AC | 814 ms
92,824 KB |
testcase_11 | AC | 1,153 ms
97,300 KB |
testcase_12 | AC | 827 ms
96,708 KB |
testcase_13 | AC | 876 ms
97,312 KB |
testcase_14 | AC | 877 ms
95,180 KB |
testcase_15 | AC | 774 ms
89,584 KB |
testcase_16 | AC | 748 ms
90,884 KB |
testcase_17 | AC | 957 ms
97,212 KB |
testcase_18 | AC | 988 ms
97,064 KB |
testcase_19 | AC | 844 ms
90,128 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long price = sc.nextInt(); List<List<Path>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; long c = sc.nextInt() + sc.nextInt() * price; graph.get(a).add(new Path(b, c)); graph.get(b).add(new Path(a, c)); } PriorityQueue<Path> queue = new PriorityQueue<>(); long[] costs = new long[n]; Arrays.fill(costs, Long.MAX_VALUE); queue.add(new Path(0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (Path x : graph.get(p.idx)) { queue.add(new Path(x.idx, x.value + p.value)); } } System.out.println(costs[n - 1] == Long.MAX_VALUE ? -1 : (costs[n - 1] + price - 1) / price); } static class Path implements Comparable<Path> { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return Long.compare(value, another.value); } } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { } } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String next() { try { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } } catch (Exception e) { e.printStackTrace(); } finally { return st.nextToken(); } } }