結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | tenten |
提出日時 | 2020-08-20 10:39:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,125 ms / 2,000 ms |
コード長 | 2,751 bytes |
コンパイル時間 | 2,408 ms |
コンパイル使用メモリ | 80,148 KB |
実行使用メモリ | 85,668 KB |
最終ジャッジ日時 | 2024-04-21 05:26:48 |
合計ジャッジ時間 | 32,425 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
37,184 KB |
testcase_01 | AC | 49 ms
37,088 KB |
testcase_02 | AC | 774 ms
65,748 KB |
testcase_03 | AC | 948 ms
81,152 KB |
testcase_04 | AC | 996 ms
84,400 KB |
testcase_05 | AC | 881 ms
85,668 KB |
testcase_06 | AC | 836 ms
85,604 KB |
testcase_07 | AC | 384 ms
54,124 KB |
testcase_08 | AC | 758 ms
85,500 KB |
testcase_09 | AC | 217 ms
48,236 KB |
testcase_10 | AC | 517 ms
63,712 KB |
testcase_11 | AC | 440 ms
55,832 KB |
testcase_12 | AC | 521 ms
53,760 KB |
testcase_13 | AC | 851 ms
66,260 KB |
testcase_14 | AC | 894 ms
69,596 KB |
testcase_15 | AC | 932 ms
77,972 KB |
testcase_16 | AC | 670 ms
57,536 KB |
testcase_17 | AC | 946 ms
78,980 KB |
testcase_18 | AC | 557 ms
54,240 KB |
testcase_19 | AC | 966 ms
79,920 KB |
testcase_20 | AC | 469 ms
52,960 KB |
testcase_21 | AC | 681 ms
55,824 KB |
testcase_22 | AC | 946 ms
72,588 KB |
testcase_23 | AC | 144 ms
40,652 KB |
testcase_24 | AC | 146 ms
41,348 KB |
testcase_25 | AC | 493 ms
52,636 KB |
testcase_26 | AC | 680 ms
63,584 KB |
testcase_27 | AC | 682 ms
60,364 KB |
testcase_28 | AC | 990 ms
72,152 KB |
testcase_29 | AC | 333 ms
47,680 KB |
testcase_30 | AC | 1,035 ms
80,192 KB |
testcase_31 | AC | 762 ms
66,036 KB |
testcase_32 | AC | 598 ms
57,276 KB |
testcase_33 | AC | 914 ms
76,052 KB |
testcase_34 | AC | 581 ms
56,892 KB |
testcase_35 | AC | 1,078 ms
78,044 KB |
testcase_36 | AC | 116 ms
39,976 KB |
testcase_37 | AC | 135 ms
41,324 KB |
testcase_38 | AC | 109 ms
39,804 KB |
testcase_39 | AC | 135 ms
41,176 KB |
testcase_40 | AC | 82 ms
38,720 KB |
testcase_41 | AC | 1,125 ms
85,648 KB |
testcase_42 | AC | 582 ms
56,364 KB |
testcase_43 | AC | 758 ms
66,388 KB |
testcase_44 | AC | 405 ms
51,624 KB |
testcase_45 | AC | 763 ms
66,060 KB |
testcase_46 | AC | 48 ms
37,296 KB |
testcase_47 | AC | 49 ms
37,192 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; } } }