結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | hiromi_ayase |
提出日時 | 2020-05-29 21:42:54 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,524 ms / 2,000 ms |
コード長 | 2,356 bytes |
コンパイル時間 | 2,760 ms |
コンパイル使用メモリ | 79,872 KB |
実行使用メモリ | 93,564 KB |
最終ジャッジ日時 | 2024-11-06 03:18:08 |
合計ジャッジ時間 | 48,907 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 133 ms
54,244 KB |
testcase_01 | AC | 146 ms
54,112 KB |
testcase_02 | AC | 1,160 ms
79,196 KB |
testcase_03 | AC | 1,425 ms
90,220 KB |
testcase_04 | AC | 1,334 ms
91,656 KB |
testcase_05 | AC | 1,414 ms
90,300 KB |
testcase_06 | AC | 1,373 ms
89,208 KB |
testcase_07 | AC | 713 ms
69,236 KB |
testcase_08 | AC | 1,178 ms
92,224 KB |
testcase_09 | AC | 442 ms
61,800 KB |
testcase_10 | AC | 838 ms
76,136 KB |
testcase_11 | AC | 685 ms
69,896 KB |
testcase_12 | AC | 677 ms
67,380 KB |
testcase_13 | AC | 1,170 ms
86,020 KB |
testcase_14 | AC | 1,314 ms
83,732 KB |
testcase_15 | AC | 1,359 ms
87,120 KB |
testcase_16 | AC | 939 ms
76,100 KB |
testcase_17 | AC | 1,366 ms
90,572 KB |
testcase_18 | AC | 899 ms
72,760 KB |
testcase_19 | AC | 1,447 ms
87,432 KB |
testcase_20 | AC | 804 ms
70,012 KB |
testcase_21 | AC | 887 ms
75,292 KB |
testcase_22 | AC | 1,364 ms
86,472 KB |
testcase_23 | AC | 205 ms
57,524 KB |
testcase_24 | AC | 227 ms
57,728 KB |
testcase_25 | AC | 652 ms
66,448 KB |
testcase_26 | AC | 1,188 ms
77,844 KB |
testcase_27 | AC | 1,084 ms
77,456 KB |
testcase_28 | AC | 1,386 ms
86,004 KB |
testcase_29 | AC | 555 ms
59,608 KB |
testcase_30 | AC | 1,428 ms
86,728 KB |
testcase_31 | AC | 1,268 ms
82,428 KB |
testcase_32 | AC | 963 ms
76,024 KB |
testcase_33 | AC | 1,343 ms
89,528 KB |
testcase_34 | AC | 889 ms
72,772 KB |
testcase_35 | AC | 1,502 ms
87,180 KB |
testcase_36 | AC | 214 ms
57,296 KB |
testcase_37 | AC | 230 ms
58,216 KB |
testcase_38 | AC | 215 ms
57,568 KB |
testcase_39 | AC | 229 ms
58,248 KB |
testcase_40 | AC | 196 ms
54,756 KB |
testcase_41 | AC | 1,524 ms
93,564 KB |
testcase_42 | AC | 892 ms
72,948 KB |
testcase_43 | AC | 1,186 ms
80,372 KB |
testcase_44 | AC | 753 ms
68,248 KB |
testcase_45 | AC | 1,091 ms
78,948 KB |
testcase_46 | AC | 129 ms
54,180 KB |
testcase_47 | AC | 132 ms
54,280 KB |
ソースコード
import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int x = sc.nextInt() - 1; int y = sc.nextInt() - 1; int[][] p = new int[n][]; for (int i = 0; i < n; i++) { p[i] = new int[] { Integer.parseInt(sc.next()), Integer.parseInt(sc.next()) }; } int[] from = new int[m]; int[] to = new int[m]; int[] w = new int[m]; for (int i = 0; i < m; i ++) { from[i] = Integer.parseInt(sc.next()) - 1; to[i] = Integer.parseInt(sc.next()) - 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; } }