結果
| 問題 |
No.1382 Travel in Mitaru city
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2021-02-07 21:12:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,711 bytes |
| コンパイル時間 | 2,293 ms |
| コンパイル使用メモリ | 78,888 KB |
| 実行使用メモリ | 167,792 KB |
| 最終ジャッジ日時 | 2024-07-04 14:27:14 |
| 合計ジャッジ時間 | 37,092 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 50 |
ソースコード
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] sa = br.readLine().split(" ");
int n = Integer.parseInt(sa[0]);
int m = Integer.parseInt(sa[1]);
int s = Integer.parseInt(sa[2]) - 1;
int t = Integer.parseInt(sa[3]) - 1;
sa = br.readLine().split(" ");
int[] p = new int[n];
for (int i = 0; i < n; i++) {
p[i] = Integer.parseInt(sa[i]);
}
List<List<Integer>> list = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
list.add(new ArrayList<>());
}
for (int i = 0; i < m; i++) {
sa = br.readLine().split(" ");
int a = Integer.parseInt(sa[0]) - 1;
int b = Integer.parseInt(sa[1]) - 1;
list.get(a).add(b);
list.get(b).add(a);
}
br.close();
int[] d = new int[list.size()];
PriorityQueue<Node> que = new PriorityQueue<Node>();
Node first = new Node(s, 0, p[s]);
que.add(first);
while (!que.isEmpty()) {
Node cur = que.poll();
if (cur.d < d[cur.v]) {
continue;
}
for (int next : list.get(cur.v)) {
int alt = d[cur.v];
if (cur.x > p[next]) {
alt++;
}
if (alt > d[next]) {
d[next] = alt;
que.add(new Node(next, alt, Math.min(cur.x, p[next])));
}
}
}
System.out.println(d[t]);
}
static class Node implements Comparable<Node> {
int v, d, x;
public Node(int v, int d, int x) {
this.v = v;
this.d = d;
this.x = x;
}
public int compareTo(Node o) {
if (d != o.d) {
return o.d - d;
}
return o.x - x;
}
}
}
ks2m