結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | tenten |
提出日時 | 2020-08-20 10:39:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,216 ms / 2,000 ms |
コード長 | 2,751 bytes |
コンパイル時間 | 2,430 ms |
コンパイル使用メモリ | 80,264 KB |
実行使用メモリ | 95,476 KB |
最終ジャッジ日時 | 2024-10-13 03:57:26 |
合計ジャッジ時間 | 34,814 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
50,360 KB |
testcase_01 | AC | 55 ms
50,192 KB |
testcase_02 | AC | 823 ms
77,292 KB |
testcase_03 | AC | 1,059 ms
91,244 KB |
testcase_04 | AC | 1,035 ms
93,524 KB |
testcase_05 | AC | 953 ms
95,476 KB |
testcase_06 | AC | 947 ms
95,204 KB |
testcase_07 | AC | 403 ms
64,396 KB |
testcase_08 | AC | 883 ms
95,460 KB |
testcase_09 | AC | 225 ms
59,760 KB |
testcase_10 | AC | 568 ms
73,112 KB |
testcase_11 | AC | 469 ms
65,556 KB |
testcase_12 | AC | 560 ms
64,080 KB |
testcase_13 | AC | 922 ms
76,076 KB |
testcase_14 | AC | 941 ms
79,096 KB |
testcase_15 | AC | 1,083 ms
88,128 KB |
testcase_16 | AC | 747 ms
57,512 KB |
testcase_17 | AC | 1,038 ms
78,764 KB |
testcase_18 | AC | 588 ms
55,572 KB |
testcase_19 | AC | 1,029 ms
80,448 KB |
testcase_20 | AC | 517 ms
52,572 KB |
testcase_21 | AC | 701 ms
57,888 KB |
testcase_22 | AC | 1,065 ms
72,684 KB |
testcase_23 | AC | 145 ms
40,884 KB |
testcase_24 | AC | 157 ms
41,180 KB |
testcase_25 | AC | 493 ms
52,428 KB |
testcase_26 | AC | 717 ms
63,680 KB |
testcase_27 | AC | 732 ms
62,756 KB |
testcase_28 | AC | 992 ms
72,156 KB |
testcase_29 | AC | 337 ms
47,844 KB |
testcase_30 | AC | 1,014 ms
80,540 KB |
testcase_31 | AC | 821 ms
66,608 KB |
testcase_32 | AC | 706 ms
57,984 KB |
testcase_33 | AC | 985 ms
74,396 KB |
testcase_34 | AC | 662 ms
56,920 KB |
testcase_35 | AC | 1,119 ms
77,900 KB |
testcase_36 | AC | 114 ms
39,728 KB |
testcase_37 | AC | 147 ms
40,920 KB |
testcase_38 | AC | 122 ms
39,720 KB |
testcase_39 | AC | 137 ms
41,372 KB |
testcase_40 | AC | 98 ms
38,812 KB |
testcase_41 | AC | 1,216 ms
85,892 KB |
testcase_42 | AC | 641 ms
66,024 KB |
testcase_43 | AC | 827 ms
75,988 KB |
testcase_44 | AC | 445 ms
62,492 KB |
testcase_45 | AC | 817 ms
75,568 KB |
testcase_46 | AC | 57 ms
50,356 KB |
testcase_47 | AC | 55 ms
50,132 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); String[] second = br.readLine().split(" ", 2); int x = Integer.parseInt(second[0]) - 1; int y = Integer.parseInt(second[1]) - 1; ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); Node[] nodes = new Node[n]; for (int i = 0; i < n; i++) { String[] line = br.readLine().split(" ", 2); nodes[i] = new Node(i, Integer.parseInt(line[0]), Integer.parseInt(line[1])); graph.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { String[] line = br.readLine().split(" ", 2); int a = Integer.parseInt(line[0]) - 1; int b = Integer.parseInt(line[1]) - 1; graph.get(a).add(b); graph.get(b).add(a); } double[] costs = new double[n]; Arrays.fill(costs, Double.MAX_VALUE); PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(x, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int next : graph.get(p.idx)) { queue.add(new Path(next, p.value + nodes[next].getDistance(nodes[p.idx]))); } } System.out.println(costs[y]); } static class Path implements Comparable<Path> { int idx; double value; public Path(int idx, double value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } static class Node { int idx; int x; int y; public Node(int idx, int x, int y) { this.idx = idx; this.x = x; this.y = y; } public double getDistance(Node another) { return Math.sqrt(Math.pow(x - another.x, 2) + Math.pow(y - another.y, 2)); } public int hashCode() { return idx; } public boolean equals(Object o) { Node n = (Node)o; return idx == n.idx; } } }