結果

問題 No.92 逃走経路
ユーザー mosmos_21mosmos_21
提出日時 2017-06-21 16:32:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,698 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 80,880 KB
実行使用メモリ 60,532 KB
最終ジャッジ日時 2024-04-10 09:06:05
合計ジャッジ時間 9,762 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 125 ms
54,296 KB
testcase_02 AC 142 ms
54,164 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 281 ms
58,776 KB
testcase_06 AC 254 ms
58,868 KB
testcase_07 AC 273 ms
58,968 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 449 ms
58,712 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

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[y]] = true;
                        }
                        if(b[z] == y && c[z] == d[x]){
                            n[x][a[y]] = 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