結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | htensai |
提出日時 | 2020-06-04 12:43:53 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,179 ms / 2,000 ms |
コード長 | 2,482 bytes |
コンパイル時間 | 2,092 ms |
コンパイル使用メモリ | 79,404 KB |
実行使用メモリ | 141,428 KB |
最終ジャッジ日時 | 2024-11-28 15:38:08 |
合計ジャッジ時間 | 32,575 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
50,416 KB |
testcase_01 | AC | 51 ms
50,456 KB |
testcase_02 | AC | 678 ms
93,960 KB |
testcase_03 | AC | 976 ms
122,204 KB |
testcase_04 | AC | 1,037 ms
124,416 KB |
testcase_05 | AC | 877 ms
133,464 KB |
testcase_06 | AC | 870 ms
133,424 KB |
testcase_07 | AC | 402 ms
74,392 KB |
testcase_08 | AC | 841 ms
136,780 KB |
testcase_09 | AC | 218 ms
62,852 KB |
testcase_10 | AC | 542 ms
95,068 KB |
testcase_11 | AC | 444 ms
77,464 KB |
testcase_12 | AC | 367 ms
74,632 KB |
testcase_13 | AC | 920 ms
101,600 KB |
testcase_14 | AC | 945 ms
102,408 KB |
testcase_15 | AC | 1,066 ms
116,400 KB |
testcase_16 | AC | 716 ms
92,260 KB |
testcase_17 | AC | 1,150 ms
124,268 KB |
testcase_18 | AC | 589 ms
77,368 KB |
testcase_19 | AC | 1,092 ms
126,548 KB |
testcase_20 | AC | 457 ms
76,488 KB |
testcase_21 | AC | 728 ms
82,296 KB |
testcase_22 | AC | 1,004 ms
108,320 KB |
testcase_23 | AC | 135 ms
54,644 KB |
testcase_24 | AC | 130 ms
54,480 KB |
testcase_25 | AC | 349 ms
73,704 KB |
testcase_26 | AC | 611 ms
92,096 KB |
testcase_27 | AC | 694 ms
92,828 KB |
testcase_28 | AC | 948 ms
109,184 KB |
testcase_29 | AC | 301 ms
64,824 KB |
testcase_30 | AC | 1,041 ms
112,412 KB |
testcase_31 | AC | 840 ms
100,268 KB |
testcase_32 | AC | 538 ms
79,780 KB |
testcase_33 | AC | 1,007 ms
111,904 KB |
testcase_34 | AC | 603 ms
80,268 KB |
testcase_35 | AC | 948 ms
113,948 KB |
testcase_36 | AC | 102 ms
51,608 KB |
testcase_37 | AC | 131 ms
53,088 KB |
testcase_38 | AC | 110 ms
51,792 KB |
testcase_39 | AC | 127 ms
53,100 KB |
testcase_40 | AC | 84 ms
51,372 KB |
testcase_41 | AC | 1,179 ms
141,428 KB |
testcase_42 | AC | 531 ms
77,928 KB |
testcase_43 | AC | 754 ms
100,460 KB |
testcase_44 | AC | 346 ms
67,244 KB |
testcase_45 | AC | 843 ms
100,204 KB |
testcase_46 | AC | 51 ms
50,492 KB |
testcase_47 | AC | 49 ms
50,444 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; Point[] points = new Point[n]; ArrayList<HashMap<Integer, Double>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { String[] line = br.readLine().split(" ", 2); points[i] = new Point(Integer.parseInt(line[0]), Integer.parseInt(line[1])); graph.add(new HashMap<>()); } 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; double distance = points[a].getDistance(points[b]); graph.get(a).put(b, distance); graph.get(b).put(a, distance); } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(x, 0)); boolean[] visited = new boolean[n]; double ans = 0; while (queue.size() > 0) { Path p = queue.poll(); if (visited[p.idx]) { continue; } visited[p.idx] = true; if (p.idx == y) { ans = p.value; break; } for (Map.Entry<Integer, Double> entry : graph.get(p.idx).entrySet()) { if (!visited[entry.getKey()]) { queue.add(new Path(entry.getKey(), p.value + entry.getValue())); } } } System.out.println(ans); } 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 Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } public double getDistance(Point p) { return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y)); } } }