結果

問題 No.1065 電柱 / Pole (Easy)
ユーザー htensaihtensai
提出日時 2020-06-04 11:58:07
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,871 bytes
コンパイル時間 2,705 ms
コンパイル使用メモリ 80,172 KB
実行使用メモリ 103,488 KB
最終ジャッジ日時 2024-05-06 06:33:01
合計ジャッジ時間 58,724 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,228 KB
testcase_01 AC 133 ms
41,220 KB
testcase_02 AC 1,345 ms
76,272 KB
testcase_03 AC 1,663 ms
100,696 KB
testcase_04 AC 1,695 ms
98,396 KB
testcase_05 AC 1,516 ms
98,456 KB
testcase_06 AC 1,551 ms
94,720 KB
testcase_07 AC 832 ms
66,552 KB
testcase_08 AC 1,575 ms
103,488 KB
testcase_09 AC 506 ms
54,276 KB
testcase_10 AC 1,097 ms
74,272 KB
testcase_11 AC 921 ms
72,012 KB
testcase_12 AC 949 ms
66,168 KB
testcase_13 AC 1,530 ms
79,080 KB
testcase_14 AC 1,529 ms
96,708 KB
testcase_15 AC 1,703 ms
98,956 KB
testcase_16 AC 1,259 ms
74,132 KB
testcase_17 AC 1,706 ms
102,800 KB
testcase_18 AC 1,163 ms
71,324 KB
testcase_19 AC 1,575 ms
91,124 KB
testcase_20 AC 997 ms
68,432 KB
testcase_21 AC 1,232 ms
68,424 KB
testcase_22 AC 1,547 ms
86,436 KB
testcase_23 AC 255 ms
52,260 KB
testcase_24 AC 275 ms
47,484 KB
testcase_25 AC 1,064 ms
63,712 KB
testcase_26 AC 1,268 ms
73,336 KB
testcase_27 AC 1,326 ms
78,556 KB
testcase_28 AC 1,614 ms
87,312 KB
testcase_29 AC 672 ms
56,156 KB
testcase_30 AC 1,740 ms
90,024 KB
testcase_31 AC 1,428 ms
81,664 KB
testcase_32 AC 1,209 ms
75,280 KB
testcase_33 AC 1,608 ms
90,024 KB
testcase_34 AC 1,200 ms
72,164 KB
testcase_35 AC 1,805 ms
87,164 KB
testcase_36 AC 228 ms
51,464 KB
testcase_37 AC 254 ms
46,256 KB
testcase_38 AC 233 ms
46,512 KB
testcase_39 AC 249 ms
46,220 KB
testcase_40 AC 207 ms
43,796 KB
testcase_41 TLE -
testcase_42 AC 1,098 ms
72,740 KB
testcase_43 AC 1,582 ms
77,712 KB
testcase_44 AC 916 ms
67,624 KB
testcase_45 AC 1,498 ms
79,072 KB
testcase_46 AC 124 ms
47,852 KB
testcase_47 AC 125 ms
41,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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;
	    Point[] points = new Point[n];
	    ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
	    for (int i = 0; i < n; i++) {
	        points[i] = new Point(sc.nextInt(), sc.nextInt());
	        graph.add(new ArrayList<>());
	    }
	    for (int i = 0; i < m; i++) {
	        int a = sc.nextInt() - 1;
	        int b = sc.nextInt() - 1;
	        graph.get(a).add(b);
	        graph.get(b).add(a);
	    }
	    PriorityQueue<Path> queue = new PriorityQueue<>();
	    queue.add(new Path(x, 0));
	    double[] costs = new double[n];
	    Arrays.fill(costs, Double.MAX_VALUE);
	    while (queue.size() > 0) {
	        Path p = queue.poll();
	        if (costs[p.idx] <= p.value) {
	            continue;
	        }
	        costs[p.idx] = p.value;
	        for (int next : graph.get(p.idx)) {
	            queue.add(new Path(next, p.value + points[p.idx].getDistance(points[next])));
	        }
	    }
		System.out.println(costs[y]);
	}
	
	static class Path implements Comparable<Path> {
	    int idx;
	    double value;
	    
	    public Path(int idx, double value) {
	        this.idx = idx;
	        this.value = value;
	    }
	    
	    public int compareTo(Path another) {
	        if (value == another.value) {
	            return 0;
	        } else if (value < another.value) {
	            return -1;
	        } else {
	            return 1;
	        }
	    }
	}
	
	static class Point {
	    int x;
	    int y;
	    
	    public Point(int x, int y) {
	        this.x = x;
	        this.y = y;
	    }
	    
	    public double getDistance(Point p) {
	        return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
	    }
	}
}
0