結果
| 問題 | No.92 逃走経路 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-30 18:29:15 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 402 ms / 5,000 ms |
| コード長 | 1,871 bytes |
| 記録 | |
| コンパイル時間 | 4,862 ms |
| コンパイル使用メモリ | 85,788 KB |
| 実行使用メモリ | 53,360 KB |
| 最終ジャッジ日時 | 2026-06-30 18:29:26 |
| 合計ジャッジ時間 | 10,339 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
public class No92 {
public static void main(String[] args) throws IOException {
String[] strings = readStr();
int n = Integer.parseInt(strings[0].split(" ")[0]);
int m = Integer.parseInt(strings[0].split(" ")[1]);
int k = Integer.parseInt(strings[0].split(" ")[2]);
int[][] c = new int[m][3];
String[] str;
int a , b, c2;
for(int i = 1;i <= m;i++) {
str = strings[i].split(" ");
a = Integer.parseInt(str[0]);
b = Integer.parseInt(str[1]);
c2 = Integer.parseInt(str[2]);
c[i-1][0] = a;
c[i-1][1] = b;
c[i-1][2] = c2;
}
int d = 0;
ArrayList<Integer> placeB = new ArrayList<Integer>();
ArrayList<Integer> placeA = new ArrayList<Integer>();
for(int i = 0;i < k;i++) {
d = Integer.parseInt(strings[m+1].split(" ")[i]);
for(int[] abc : c) {
if(abc[2] == d) {
if(i == 0) {
placeA.add(abc[0]);
placeA.add(abc[1]);
continue;
}
if(placeB.contains(abc[0]) && !placeA.contains(abc[1])) {
placeA.add(abc[1]);
}
if(placeB.contains(abc[1]) && !placeA.contains(abc[0])) {
placeA.add(abc[0]);
}
}
}
placeB = placeA;
placeA = new ArrayList<Integer>();
}
System.out.println(placeB.size());
Collections.sort(placeB);
for(int p :placeB) {
System.out.print(p + " ");
}
System.out.println();
}
public static String[] readStr() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<>();
do {
list.add(br.readLine());
}while(br.ready());
br.close();
String[] text = new String[list.size()];
list.toArray(text);
return text;
}
}