結果
| 問題 |
No.1382 Travel in Mitaru city
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-02-08 11:09:56 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,632 bytes |
| コンパイル時間 | 2,277 ms |
| コンパイル使用メモリ | 79,136 KB |
| 実行使用メモリ | 225,160 KB |
| 最終ジャッジ日時 | 2024-07-05 07:24:53 |
| 合計ジャッジ時間 | 7,892 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 3 TLE * 1 -- * 64 |
ソースコード
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 s = sc.nextInt() - 1;
int t = sc.nextInt() - 1;
Town[] towns = new Town[n];
ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
towns[i] = new Town(i, 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<Town> queue = new PriorityQueue<>();
queue.add(towns[s]);
boolean[] visited = new boolean[n];
int score = Integer.MAX_VALUE;
int count = 0;
while (queue.size() > 0) {
Town y = queue.poll();
if (score > y.value) {
score = y.value;
count++;
}
visited[y.idx] = true;;
for (int x : graph.get(y.idx)) {
if (!visited[x]) {
queue.add(towns[x]);
}
}
}
System.out.println(count - 1);
}
static class Town implements Comparable<Town> {
int idx;
int value;
public Town(int idx, int value) {
this.idx = idx;
this.value = value;
}
public int compareTo(Town another) {
return another.value - value;
}
}
}
tenten