結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-07-29 08:22:43 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 271 ms / 5,000 ms |
| コード長 | 2,318 bytes |
| コンパイル時間 | 2,456 ms |
| コンパイル使用メモリ | 80,144 KB |
| 実行使用メモリ | 48,976 KB |
| 最終ジャッジ日時 | 2024-07-19 00:09:01 |
| 合計ジャッジ時間 | 6,910 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
TreeSet<Integer> current = new TreeSet<>();
ArrayList<ArrayList<Path>> graph = new ArrayList<>();
for (int i = 0; i < n; i++) {
current.add(i);
graph.add(new ArrayList<>());
}
for (int i = 0; i < m; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
int c = sc.nextInt();
graph.get(a).add(new Path(b, c));
graph.get(b).add(new Path(a, c));
}
while (k-- > 0) {
int x = sc.nextInt();
TreeSet<Integer> next = new TreeSet();
for (int y : current) {
for (Path z : graph.get(y)) {
if (z.value == x) {
next.add(z.idx);
}
}
}
current = next;
}
StringBuilder sb = new StringBuilder();
sb.append(current.size()).append("\n");
boolean isFirst = true;
for (int x : current) {
if (!isFirst) {
sb.append(" ");
}
isFirst = false;
sb.append(x + 1);
}
System.out.println(sb);
}
static class Path {
int idx;
int value;
public Path(int idx, int value) {
this.idx = idx;
this.value = value;
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten