結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | mikit |
提出日時 | 2020-05-29 22:13:14 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,090 ms / 2,000 ms |
コード長 | 5,728 bytes |
コンパイル時間 | 2,563 ms |
コンパイル使用メモリ | 97,508 KB |
実行使用メモリ | 98,584 KB |
最終ジャッジ日時 | 2024-04-23 22:53:09 |
合計ジャッジ時間 | 29,652 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
51,424 KB |
testcase_01 | AC | 70 ms
51,244 KB |
testcase_02 | AC | 693 ms
77,772 KB |
testcase_03 | AC | 851 ms
94,664 KB |
testcase_04 | AC | 959 ms
94,152 KB |
testcase_05 | AC | 618 ms
90,092 KB |
testcase_06 | AC | 637 ms
90,236 KB |
testcase_07 | AC | 291 ms
63,688 KB |
testcase_08 | AC | 723 ms
95,112 KB |
testcase_09 | AC | 210 ms
57,400 KB |
testcase_10 | AC | 409 ms
75,508 KB |
testcase_11 | AC | 324 ms
66,928 KB |
testcase_12 | AC | 303 ms
62,908 KB |
testcase_13 | AC | 712 ms
74,832 KB |
testcase_14 | AC | 850 ms
79,208 KB |
testcase_15 | AC | 1,001 ms
88,344 KB |
testcase_16 | AC | 564 ms
67,264 KB |
testcase_17 | AC | 1,040 ms
92,860 KB |
testcase_18 | AC | 417 ms
64,104 KB |
testcase_19 | AC | 975 ms
89,984 KB |
testcase_20 | AC | 398 ms
64,888 KB |
testcase_21 | AC | 523 ms
64,524 KB |
testcase_22 | AC | 882 ms
87,928 KB |
testcase_23 | AC | 134 ms
54,240 KB |
testcase_24 | AC | 146 ms
54,336 KB |
testcase_25 | AC | 341 ms
62,308 KB |
testcase_26 | AC | 610 ms
71,860 KB |
testcase_27 | AC | 551 ms
69,840 KB |
testcase_28 | AC | 870 ms
79,068 KB |
testcase_29 | AC | 245 ms
56,924 KB |
testcase_30 | AC | 930 ms
88,592 KB |
testcase_31 | AC | 643 ms
77,164 KB |
testcase_32 | AC | 537 ms
71,876 KB |
testcase_33 | AC | 989 ms
90,372 KB |
testcase_34 | AC | 493 ms
65,436 KB |
testcase_35 | AC | 833 ms
85,524 KB |
testcase_36 | AC | 111 ms
52,692 KB |
testcase_37 | AC | 136 ms
55,300 KB |
testcase_38 | AC | 114 ms
52,656 KB |
testcase_39 | AC | 137 ms
55,264 KB |
testcase_40 | AC | 93 ms
52,236 KB |
testcase_41 | AC | 1,090 ms
98,584 KB |
testcase_42 | AC | 431 ms
67,080 KB |
testcase_43 | AC | 703 ms
79,260 KB |
testcase_44 | AC | 358 ms
64,952 KB |
testcase_45 | AC | 660 ms
78,500 KB |
testcase_46 | AC | 66 ms
51,360 KB |
testcase_47 | AC | 62 ms
51,152 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); } } } }