結果

問題 No.92 逃走経路
ユーザー mosmos_21mosmos_21
提出日時 2017-06-21 16:39:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 665 ms / 5,000 ms
コード長 1,698 bytes
コンパイル時間 3,771 ms
コンパイル使用メモリ 79,872 KB
実行使用メモリ 59,164 KB
最終ジャッジ日時 2024-04-10 09:06:34
合計ジャッジ時間 11,080 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 654 ms
59,036 KB
testcase_01 AC 137 ms
54,112 KB
testcase_02 AC 152 ms
54,128 KB
testcase_03 AC 152 ms
54,488 KB
testcase_04 AC 154 ms
54,504 KB
testcase_05 AC 295 ms
58,640 KB
testcase_06 AC 299 ms
58,684 KB
testcase_07 AC 293 ms
58,788 KB
testcase_08 AC 228 ms
55,340 KB
testcase_09 AC 273 ms
56,900 KB
testcase_10 AC 474 ms
58,880 KB
testcase_11 AC 497 ms
58,884 KB
testcase_12 AC 665 ms
58,792 KB
testcase_13 AC 268 ms
54,900 KB
testcase_14 AC 295 ms
56,928 KB
testcase_15 AC 360 ms
57,012 KB
testcase_16 AC 432 ms
57,120 KB
testcase_17 AC 634 ms
58,944 KB
testcase_18 AC 469 ms
59,164 KB
testcase_19 AC 393 ms
58,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int N = in.nextInt(), M = in.nextInt(), K = in.nextInt();
        int[] a = new int[M + 1], b = new int[M + 1], c = new int[M + 1];
        for (int i = 1; i < M + 1; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
            c[i] = in.nextInt();
        }
        int[] d = new int[K + 1];
        for(int i = 1; i < K + 1; i++){
            d[i] = in.nextInt();
        }
        boolean[][] n = new boolean[K + 1][N + 1];
        Arrays.fill(n[0], true);
        for(int i = 1; i < K + 1; i++){
            Arrays.fill(n[i], false);
        }
        
        for(int x = 1; x < K + 1; x++){
            for(int y = 1; y < N + 1; y++){
                for(int z = 1; z < M + 1; z++){
                    if(n[x - 1][y]){
                        if(a[z] == y && c[z] == d[x]){
                            n[x][b[z]] = true;
                        }
                        if(b[z] == y && c[z] == d[x]){
                            n[x][a[z]] = true;
                        }
                    }
                }
            }
        }
        int sum = 0;
        for(int i = 1; i < N + 1; i++){
            if(n[K][i]){
                sum++;
            }
        }
        System.out.println(sum);
        boolean t = true;
        for(int i = 1; i < N + 1; i++){
            if(t && n[K][i]){
                System.out.print(i);
                t = false;
            }else if(n[K][i]){
                System.out.print(" " + i);
            }
        }
        System.out.println();
    }
}
0