結果

問題 No.92 逃走経路
ユーザー k_kadorak_kadora
提出日時 2015-06-24 02:32:24
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,326 bytes
コンパイル時間 4,548 ms
コンパイル使用メモリ 79,060 KB
実行使用メモリ 61,964 KB
最終ジャッジ日時 2023-09-22 00:24:22
合計ジャッジ時間 11,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 125 ms
55,636 KB
testcase_02 AC 124 ms
55,812 KB
testcase_03 AC 125 ms
56,152 KB
testcase_04 AC 128 ms
55,808 KB
testcase_05 AC 255 ms
60,440 KB
testcase_06 AC 240 ms
59,784 KB
testcase_07 AC 244 ms
60,072 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

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();
		k = sc.nextInt();
		m = sc.nextInt();
		int[] town = new int[n];
		int[] a = new int[k];
		int[] b = new int[k];
		int[] c = new int[k];
		int[] d = new int[m];
		for(int i = 0;i<k;i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		for(int i = 0; i<m;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