結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | mikit |
提出日時 | 2020-05-29 22:13:14 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,196 ms / 2,000 ms |
コード長 | 5,728 bytes |
コンパイル時間 | 4,268 ms |
コンパイル使用メモリ | 92,320 KB |
実行使用メモリ | 95,512 KB |
最終ジャッジ日時 | 2024-11-06 05:10:13 |
合計ジャッジ時間 | 35,676 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
51,388 KB |
testcase_01 | AC | 84 ms
51,412 KB |
testcase_02 | AC | 919 ms
79,468 KB |
testcase_03 | AC | 1,093 ms
93,900 KB |
testcase_04 | AC | 1,034 ms
93,376 KB |
testcase_05 | AC | 796 ms
90,192 KB |
testcase_06 | AC | 709 ms
89,548 KB |
testcase_07 | AC | 357 ms
66,156 KB |
testcase_08 | AC | 839 ms
95,512 KB |
testcase_09 | AC | 244 ms
56,952 KB |
testcase_10 | AC | 498 ms
76,072 KB |
testcase_11 | AC | 388 ms
66,416 KB |
testcase_12 | AC | 368 ms
62,668 KB |
testcase_13 | AC | 908 ms
75,624 KB |
testcase_14 | AC | 1,063 ms
80,252 KB |
testcase_15 | AC | 1,150 ms
87,188 KB |
testcase_16 | AC | 714 ms
66,716 KB |
testcase_17 | AC | 1,069 ms
81,316 KB |
testcase_18 | AC | 610 ms
65,304 KB |
testcase_19 | AC | 1,150 ms
88,492 KB |
testcase_20 | AC | 501 ms
65,024 KB |
testcase_21 | AC | 606 ms
65,060 KB |
testcase_22 | AC | 1,033 ms
80,952 KB |
testcase_23 | AC | 160 ms
53,712 KB |
testcase_24 | AC | 167 ms
54,264 KB |
testcase_25 | AC | 378 ms
62,832 KB |
testcase_26 | AC | 803 ms
73,416 KB |
testcase_27 | AC | 770 ms
71,252 KB |
testcase_28 | AC | 919 ms
77,556 KB |
testcase_29 | AC | 320 ms
61,488 KB |
testcase_30 | AC | 1,196 ms
88,544 KB |
testcase_31 | AC | 761 ms
77,292 KB |
testcase_32 | AC | 672 ms
72,056 KB |
testcase_33 | AC | 1,103 ms
87,848 KB |
testcase_34 | AC | 589 ms
64,256 KB |
testcase_35 | AC | 1,032 ms
82,760 KB |
testcase_36 | AC | 126 ms
52,592 KB |
testcase_37 | AC | 167 ms
55,516 KB |
testcase_38 | AC | 134 ms
52,624 KB |
testcase_39 | AC | 170 ms
55,356 KB |
testcase_40 | AC | 112 ms
52,484 KB |
testcase_41 | AC | 1,177 ms
93,788 KB |
testcase_42 | AC | 632 ms
67,328 KB |
testcase_43 | AC | 757 ms
76,168 KB |
testcase_44 | AC | 463 ms
65,056 KB |
testcase_45 | AC | 919 ms
78,672 KB |
testcase_46 | AC | 78 ms
51,456 KB |
testcase_47 | AC | 80 ms
51,368 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.stream.IntStream; import java.util.Arrays; import java.util.PriorityQueue; import java.util.OptionalInt; import java.util.ArrayList; import java.io.BufferedOutputStream; import java.util.AbstractCollection; import java.nio.charset.Charset; import java.util.StringTokenizer; import java.io.OutputStreamWriter; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.UncheckedIOException; import java.util.List; import java.util.stream.Stream; import java.io.Writer; import java.io.BufferedReader; import java.util.Comparator; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author mikit */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; LightScanner in = new LightScanner(inputStream); LightWriter out = new LightWriter(outputStream); YC1065 solver = new YC1065(); solver.solve(1, in, out); out.close(); } static class YC1065 { public void solve(int testNumber, LightScanner in, LightWriter out) { int n = in.ints(), m = in.ints(), start = in.ints() - 1, goal = in.ints() - 1; int[] px = new int[n], py = new int[n]; in.ints(px, py); List<List<Integer>> adj = new ArrayList<>(); for (int i = 0; i < n; i++) adj.add(new ArrayList<>()); for (int i = 0; i < m; i++) { int x = in.ints() - 1, y = in.ints() - 1; adj.get(x).add(y); adj.get(y).add(x); } double[] dist = new double[n]; Arrays.fill(dist, Double.MAX_VALUE); PriorityQueue<Integer> q = new PriorityQueue<>(Comparator.comparing(x -> dist[x])); dist[start] = 0; q.offer(start); while (!q.isEmpty()) { int now = q.poll(); for (int nxt : adj.get(now)) { double d = dist[now] + Math.hypot(px[now] - px[nxt], py[now] - py[nxt]); if (dist[nxt] <= d) continue; dist[nxt] = d; q.offer(nxt); } } out.ans(dist[goal], 10).ln(); } } static class LightWriter implements AutoCloseable { private final Writer out; private boolean autoflush = false; private boolean breaked = true; public LightWriter(Writer out) { this.out = out; } public LightWriter(OutputStream out) { this(new OutputStreamWriter(new BufferedOutputStream(out), Charset.defaultCharset())); } public LightWriter print(char c) { try { out.write(c); breaked = false; } catch (IOException ex) { throw new UncheckedIOException(ex); } return this; } public LightWriter print(String s) { try { out.write(s, 0, s.length()); breaked = false; } catch (IOException ex) { throw new UncheckedIOException(ex); } return this; } public LightWriter ans(double x, int n) { if (!breaked) { print(' '); } if (x < 0) { print('-'); x = -x; } x += Math.pow(10, -n) / 2; print(Long.toString((long) x)).print('.'); x -= (long) x; for (int i = 0; i < n; i++) { x *= 10; print((char) ('0' + ((int) x))); x -= (int) x; } return this; } public LightWriter ln() { print(System.lineSeparator()); breaked = true; if (autoflush) { try { out.flush(); } catch (IOException ex) { throw new UncheckedIOException(ex); } } return this; } public void close() { try { out.close(); } catch (IOException ex) { throw new UncheckedIOException(ex); } } } static class LightScanner implements AutoCloseable { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public LightScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); } public String string() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new UncheckedIOException(e); } } return tokenizer.nextToken(); } public int ints() { return Integer.parseInt(string()); } public void ints(int[]... arrays) { int l = Arrays.stream(arrays).mapToInt(a -> a.length).min().orElse(0); for (int i = 0; i < l; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = ints(); } } } public void close() { try { this.reader.close(); } catch (IOException ex) { throw new UncheckedIOException(ex); } } } }