結果

問題 No.92 逃走経路
ユーザー tsunabittsunabit
提出日時 2020-02-24 00:26:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 286 ms / 5,000 ms
コード長 1,266 bytes
コンパイル時間 4,960 ms
コンパイル使用メモリ 83,748 KB
実行使用メモリ 47,604 KB
最終ジャッジ日時 2024-04-19 08:21:05
合計ジャッジ時間 9,467 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
46,612 KB
testcase_01 AC 143 ms
41,996 KB
testcase_02 AC 142 ms
41,760 KB
testcase_03 AC 143 ms
42,116 KB
testcase_04 AC 127 ms
41,980 KB
testcase_05 AC 268 ms
47,128 KB
testcase_06 AC 242 ms
45,996 KB
testcase_07 AC 261 ms
46,208 KB
testcase_08 AC 213 ms
43,332 KB
testcase_09 AC 235 ms
44,336 KB
testcase_10 AC 278 ms
47,604 KB
testcase_11 AC 275 ms
47,204 KB
testcase_12 AC 286 ms
46,908 KB
testcase_13 AC 222 ms
44,072 KB
testcase_14 AC 236 ms
44,200 KB
testcase_15 AC 243 ms
44,568 KB
testcase_16 AC 246 ms
45,276 KB
testcase_17 AC 266 ms
47,076 KB
testcase_18 AC 261 ms
47,012 KB
testcase_19 AC 252 ms
46,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No92 {
	public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int m = sc.nextInt();
			int k = sc.nextInt();
			
			int[] a = new int[m];
			int[] b = new int[m];
			int[] c = new int[m];
			for(int i = 0; i < m; i++) {
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
				c[i] = sc.nextInt();
			}
			
			int[] d = new int[k];
			for(int i = 0; i < k; i++) {
				d[i] = sc.nextInt();
			}
			
			int[][] dp = new int[k][n];
			for(int[] x: dp){
			    java.util.Arrays.fill(x, 0);
			}
			
			// d[0]処理
			for(int i = 0; i < m; i++) {
				if(d[0] == c[i]) {
					dp[0][a[i]-1] = 1;
					dp[0][b[i]-1] = 1;
				}
			}
			
			for(int i = 1; i < k; i++) {
				for(int j = 0; j < m; j++) {
					if(d[i] == c[j]) {
						if(dp[i-1][a[j]-1] == 1) dp[i][b[j]-1] = 1;
						if(dp[i-1][b[j]-1] == 1) dp[i][a[j]-1] = 1;
					}
				}
			}
			
			int ans = 0;
			for(int i = 0; i < n; i++) ans += dp[k-1][i];
			System.out.println(ans);
			
			for(int i = 0; i < n; i++) {
				if(dp[k-1][i] == 1) System.out.print(i+1 + " ");
			}
			System.out.println("");
		} catch(Exception e) {
			System.out.println(e);
            return;
		}
	}
}
0