結果

問題 No.92 逃走経路
ユーザー yuki2006yuki2006
提出日時 2015-01-25 18:07:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 241 ms / 5,000 ms
コード長 1,661 bytes
コンパイル時間 4,223 ms
コンパイル使用メモリ 74,408 KB
実行使用メモリ 61,340 KB
最終ジャッジ日時 2023-09-05 06:18:47
合計ジャッジ時間 9,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 231 ms
59,424 KB
testcase_01 AC 127 ms
55,948 KB
testcase_02 AC 125 ms
55,804 KB
testcase_03 AC 125 ms
55,656 KB
testcase_04 AC 124 ms
55,712 KB
testcase_05 AC 237 ms
59,340 KB
testcase_06 AC 224 ms
58,908 KB
testcase_07 AC 224 ms
59,232 KB
testcase_08 AC 186 ms
56,260 KB
testcase_09 AC 193 ms
56,364 KB
testcase_10 AC 234 ms
59,320 KB
testcase_11 AC 233 ms
59,448 KB
testcase_12 AC 241 ms
59,464 KB
testcase_13 AC 195 ms
56,112 KB
testcase_14 AC 203 ms
59,112 KB
testcase_15 AC 210 ms
59,168 KB
testcase_16 AC 216 ms
59,144 KB
testcase_17 AC 231 ms
61,340 KB
testcase_18 AC 216 ms
59,292 KB
testcase_19 AC 227 ms
59,356 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[N+1];
            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+1; j++) {
            if (prev[j]) {
                count++;
            }
        }
        System.out.println(count);

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

    }

}
0