結果

問題 No.92 逃走経路
ユーザー yuki2006yuki2006
提出日時 2015-01-25 18:04:10
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 4,641 ms
コンパイル使用メモリ 79,000 KB
実行使用メモリ 62,000 KB
最終ジャッジ日時 2023-09-05 06:18:05
合計ジャッジ時間 10,215 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 237 ms
59,052 KB
testcase_01 WA -
testcase_02 AC 124 ms
56,012 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 197 ms
57,980 KB
testcase_14 AC 202 ms
58,940 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 236 ms
59,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Yuki092 {
    public static void main(String[] args) {
        Yuki092 hoge = new Yuki092();
    }

    Yuki092() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int K = scanner.nextInt();

        int[] a = new int[M];
        int[] b = new int[M];
        int[] c = new int[M];


        boolean[] prev = new boolean[N + 1];

        Arrays.fill(prev, true);

        for (int i = 0; i < M; i++) {

            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
            c[i] = scanner.nextInt();
        }
        for (int i = 0; i < K; i++) {
            int d = scanner.nextInt();

            boolean[] next = new boolean[1001];
            for (int j = 0; j < M; j++) {
                if (c[j] == d) {
                    int u = a[j], v = b[j];
                    if (prev[u]) {
                        next[v] = true;
                    }
                    if (prev[v]) {
                        next[u] = true;
                    }
                }
            }
            prev = next;
        }
        int count = 0;
        for (int j = 0; j < N; j++) {
            if (prev[j]) {
                count++;
            }
        }
        System.out.println(count);

        StringBuilder ans = new StringBuilder();
        for (int j = 0; j < N; j++) {
            if (prev[j]) {
                if (ans.length() > 0) {
                    ans.append(" ");
                }
                ans.append(j);
            }
        }
        System.out.println(ans);

    }

}
0