結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 125 ms
55,776 KB
testcase_02 AC 129 ms
55,876 KB
testcase_03 AC 128 ms
55,832 KB
testcase_04 AC 125 ms
55,856 KB
testcase_05 AC 279 ms
60,288 KB
testcase_06 AC 245 ms
59,788 KB
testcase_07 AC 248 ms
60,008 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();
		m = sc.nextInt();
		k = sc.nextInt();
		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