結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | hiromi_ayase |
提出日時 | 2020-05-29 21:50:16 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,106 ms / 2,000 ms |
コード長 | 3,373 bytes |
コンパイル時間 | 2,631 ms |
コンパイル使用メモリ | 79,328 KB |
実行使用メモリ | 89,752 KB |
最終ジャッジ日時 | 2024-11-06 03:47:50 |
合計ジャッジ時間 | 31,319 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
50,452 KB |
testcase_01 | AC | 59 ms
50,180 KB |
testcase_02 | AC | 742 ms
73,324 KB |
testcase_03 | AC | 937 ms
82,336 KB |
testcase_04 | AC | 960 ms
82,540 KB |
testcase_05 | AC | 805 ms
83,488 KB |
testcase_06 | AC | 770 ms
81,364 KB |
testcase_07 | AC | 340 ms
65,392 KB |
testcase_08 | AC | 722 ms
84,948 KB |
testcase_09 | AC | 221 ms
56,124 KB |
testcase_10 | AC | 452 ms
69,288 KB |
testcase_11 | AC | 372 ms
65,172 KB |
testcase_12 | AC | 309 ms
60,796 KB |
testcase_13 | AC | 777 ms
75,844 KB |
testcase_14 | AC | 863 ms
79,328 KB |
testcase_15 | AC | 900 ms
80,784 KB |
testcase_16 | AC | 602 ms
69,120 KB |
testcase_17 | AC | 978 ms
83,200 KB |
testcase_18 | AC | 479 ms
65,172 KB |
testcase_19 | AC | 1,038 ms
79,488 KB |
testcase_20 | AC | 432 ms
63,024 KB |
testcase_21 | AC | 521 ms
67,376 KB |
testcase_22 | AC | 877 ms
79,276 KB |
testcase_23 | AC | 128 ms
52,252 KB |
testcase_24 | AC | 133 ms
52,244 KB |
testcase_25 | AC | 304 ms
62,348 KB |
testcase_26 | AC | 683 ms
71,632 KB |
testcase_27 | AC | 681 ms
69,568 KB |
testcase_28 | AC | 964 ms
80,420 KB |
testcase_29 | AC | 268 ms
61,416 KB |
testcase_30 | AC | 1,020 ms
82,024 KB |
testcase_31 | AC | 852 ms
74,232 KB |
testcase_32 | AC | 599 ms
67,692 KB |
testcase_33 | AC | 945 ms
79,712 KB |
testcase_34 | AC | 515 ms
65,664 KB |
testcase_35 | AC | 993 ms
79,744 KB |
testcase_36 | AC | 118 ms
52,364 KB |
testcase_37 | AC | 147 ms
53,412 KB |
testcase_38 | AC | 121 ms
52,544 KB |
testcase_39 | AC | 146 ms
53,352 KB |
testcase_40 | AC | 96 ms
51,632 KB |
testcase_41 | AC | 1,106 ms
89,752 KB |
testcase_42 | AC | 508 ms
65,836 KB |
testcase_43 | AC | 721 ms
70,932 KB |
testcase_44 | AC | 390 ms
63,332 KB |
testcase_45 | AC | 738 ms
69,776 KB |
testcase_46 | AC | 58 ms
50,248 KB |
testcase_47 | AC | 63 ms
50,700 KB |
ソースコード
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.util.TreeSet; public class Main { private static java.io.InputStream is = System.in; private static java.io.PrintWriter out = new java.io.PrintWriter(System.out); private static java.util.StringTokenizer tokenizer = null; private static java.io.BufferedReader reader; static { reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768); } public static String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new java.util.StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private static int ni() { return Integer.parseInt(next()); } public static void main(String[] args) { int n = ni(); int m = ni(); int x = ni() - 1; int y = ni() - 1; int[][] p = new int[n][]; for (int i = 0; i < n; i++) { p[i] = new int[] { ni(), ni() }; } int[] from = new int[m]; int[] to = new int[m]; int[] w = new int[m]; for (int i = 0; i < m; i++) { from[i] = ni() - 1; to[i] = ni() - 1; int dx = p[from[i]][0] - p[to[i]][0]; int dy = p[from[i]][1] - p[to[i]][1]; w[i] = dx * dx + dy * dy; } int[][][] g = packWU(n, from, to, w); double[] d = dijk(g, x); System.out.println(d[y]); } public static int[][][] packWU(int n, int[] from, int[] to, int[] w) { return packWU(n, from, to, w, from.length); } public static int[][][] packWU(int n, int[] from, int[] to, int[] w, int sup) { int[][][] g = new int[n][][]; int[] p = new int[n]; for (int i = 0; i < sup; i++) p[from[i]]++; for (int i = 0; i < sup; i++) p[to[i]]++; for (int i = 0; i < n; i++) g[i] = new int[p[i]][2]; for (int i = 0; i < sup; i++) { --p[from[i]]; g[from[i]][p[from[i]]][0] = to[i]; g[from[i]][p[from[i]]][1] = w[i]; --p[to[i]]; g[to[i]][p[to[i]]][0] = from[i]; g[to[i]][p[to[i]]][1] = w[i]; } return g; } public static double[] dijk(int[][][] g, int from) { int n = g.length; final double[] td = new double[n]; Arrays.fill(td, Integer.MAX_VALUE); TreeSet<Integer> q = new TreeSet<Integer>(new Comparator<Integer>() { public int compare(Integer a, Integer b) { if (td[a] - td[b] != 0) return Double.compare(td[a], td[b]); return a - b; } }); q.add(from); td[from] = 0; while (q.size() > 0) { int cur = q.pollFirst(); for (int i = 0; i < g[cur].length; i++) { int next = g[cur][i][0]; double nd = td[cur] + Math.sqrt(g[cur][i][1]); if (nd < td[next]) { q.remove(next); td[next] = nd; q.add(next); } } } return td; } }