結果

問題 No.92 逃走経路
ユーザー k_kadorak_kadora
提出日時 2015-06-24 03:21:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 645 ms / 5,000 ms
コード長 1,299 bytes
コンパイル時間 3,428 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 60,740 KB
最終ジャッジ日時 2023-09-22 00:24:49
合計ジャッジ時間 10,875 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 435 ms
60,300 KB
testcase_01 AC 122 ms
55,532 KB
testcase_02 AC 121 ms
56,416 KB
testcase_03 AC 124 ms
55,828 KB
testcase_04 AC 120 ms
55,908 KB
testcase_05 AC 249 ms
60,024 KB
testcase_06 AC 238 ms
59,644 KB
testcase_07 AC 243 ms
60,588 KB
testcase_08 AC 189 ms
56,716 KB
testcase_09 AC 248 ms
56,796 KB
testcase_10 AC 453 ms
60,740 KB
testcase_11 AC 483 ms
60,344 KB
testcase_12 AC 645 ms
60,124 KB
testcase_13 AC 237 ms
56,780 KB
testcase_14 AC 269 ms
59,384 KB
testcase_15 AC 318 ms
59,116 KB
testcase_16 AC 305 ms
59,916 KB
testcase_17 AC 438 ms
60,176 KB
testcase_18 AC 358 ms
60,472 KB
testcase_19 AC 344 ms
60,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Yuki92{
	public static void main(String[] arg){
		Scanner sc = new Scanner(System.in);
		int n,k,m,res = 0,count = 0;
		boolean flag=false;
		n = sc.nextInt();
		m = sc.nextInt();
		k = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		int[] c = new int[m];
		int[] d = new int[k];
		for(int i = 0;i<m;i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		for(int i = 0; i<k;i++){
			d[i] = sc.nextInt();
		}
		int[] prev = new int[n];
		int[] next = new int[n];
		for(int i = 0;i<m;i++){
			if(c[i] == d[0]){
				prev[a[i]-1] = 1;
				prev[b[i]-1] = 1;
			}
		}
		for(int i = 1;i<k;i++){
			for(int j = 0;j<n;j++){
				if(prev[j] == 1){
					for(int l = 0;l<m;l++){
						if(d[i] == c[l]){
							if(a[l] == j + 1)next[b[l]-1]=1;
							if(b[l] == j + 1)next[a[l]-1]=1;
						}
					}
				}
			}
			for(int j = 0;j<n;j++){
				prev[j] = next[j];
				next[j] = 0;
			}
		}
		for(int i = 0;i<n;i++){
			if(prev[i] == 1)res++;
		}
		System.out.println(res);
		for(int i = 0;i<n;i++){
			if(count < res - 1&& prev[i] == 1){
				System.out.print(i+1);
				System.out.print(" ");
				flag = true;
			}
			if(count == res-1 && prev[i] == 1)System.out.println(i+1);
			if(flag){
				count++;
				flag = false;
			}
		}
	}
}
0