結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | hiromi_ayase |
提出日時 | 2020-05-29 21:41:13 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,939 ms / 2,000 ms |
コード長 | 2,296 bytes |
コンパイル時間 | 3,080 ms |
コンパイル使用メモリ | 79,496 KB |
実行使用メモリ | 97,644 KB |
最終ジャッジ日時 | 2024-11-06 03:06:36 |
合計ジャッジ時間 | 58,598 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 140 ms
54,184 KB |
testcase_01 | AC | 147 ms
54,276 KB |
testcase_02 | AC | 1,464 ms
84,204 KB |
testcase_03 | AC | 1,798 ms
96,416 KB |
testcase_04 | AC | 1,699 ms
94,576 KB |
testcase_05 | AC | 1,783 ms
91,200 KB |
testcase_06 | AC | 1,736 ms
90,432 KB |
testcase_07 | AC | 862 ms
72,652 KB |
testcase_08 | AC | 1,633 ms
95,128 KB |
testcase_09 | AC | 572 ms
61,688 KB |
testcase_10 | AC | 1,192 ms
80,592 KB |
testcase_11 | AC | 920 ms
75,856 KB |
testcase_12 | AC | 842 ms
67,372 KB |
testcase_13 | AC | 1,588 ms
85,312 KB |
testcase_14 | AC | 1,611 ms
89,500 KB |
testcase_15 | AC | 1,789 ms
90,384 KB |
testcase_16 | AC | 1,324 ms
78,904 KB |
testcase_17 | AC | 1,738 ms
93,916 KB |
testcase_18 | AC | 1,025 ms
75,876 KB |
testcase_19 | AC | 1,758 ms
90,344 KB |
testcase_20 | AC | 1,020 ms
74,740 KB |
testcase_21 | AC | 1,205 ms
77,652 KB |
testcase_22 | AC | 1,678 ms
91,076 KB |
testcase_23 | AC | 254 ms
57,708 KB |
testcase_24 | AC | 264 ms
57,580 KB |
testcase_25 | AC | 822 ms
66,380 KB |
testcase_26 | AC | 1,337 ms
80,688 KB |
testcase_27 | AC | 1,384 ms
82,712 KB |
testcase_28 | AC | 1,629 ms
88,916 KB |
testcase_29 | AC | 657 ms
61,724 KB |
testcase_30 | AC | 1,732 ms
90,004 KB |
testcase_31 | AC | 1,576 ms
84,772 KB |
testcase_32 | AC | 1,205 ms
78,068 KB |
testcase_33 | AC | 1,700 ms
93,060 KB |
testcase_34 | AC | 1,109 ms
77,116 KB |
testcase_35 | AC | 1,755 ms
90,108 KB |
testcase_36 | AC | 238 ms
58,008 KB |
testcase_37 | AC | 258 ms
58,164 KB |
testcase_38 | AC | 245 ms
58,224 KB |
testcase_39 | AC | 265 ms
58,888 KB |
testcase_40 | AC | 213 ms
56,904 KB |
testcase_41 | AC | 1,939 ms
97,644 KB |
testcase_42 | AC | 1,097 ms
76,268 KB |
testcase_43 | AC | 1,483 ms
84,532 KB |
testcase_44 | AC | 919 ms
72,504 KB |
testcase_45 | AC | 1,472 ms
81,276 KB |
testcase_46 | AC | 140 ms
53,852 KB |
testcase_47 | AC | 139 ms
54,176 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[] { sc.nextInt(), sc.nextInt() }; } int[] from = new int[m]; int[] to = new int[m]; int[] w = new int[m]; for (int i = 0; i < m; i ++) { from[i] = sc.nextInt() - 1; to[i] = sc.nextInt() - 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; } }