結果

問題 No.92 逃走経路
ユーザー takeya_okinotakeya_okino
提出日時 2017-06-17 11:57:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 255 ms / 5,000 ms
コード長 1,502 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 78,184 KB
実行使用メモリ 61,588 KB
最終ジャッジ日時 2024-04-08 17:26:02
合計ジャッジ時間 7,381 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 248 ms
61,396 KB
testcase_01 AC 119 ms
56,692 KB
testcase_02 AC 131 ms
57,840 KB
testcase_03 AC 133 ms
57,828 KB
testcase_04 AC 130 ms
57,712 KB
testcase_05 AC 241 ms
61,492 KB
testcase_06 AC 234 ms
61,376 KB
testcase_07 AC 236 ms
61,216 KB
testcase_08 AC 187 ms
60,240 KB
testcase_09 AC 211 ms
58,708 KB
testcase_10 AC 251 ms
61,588 KB
testcase_11 AC 241 ms
61,264 KB
testcase_12 AC 255 ms
61,508 KB
testcase_13 AC 212 ms
60,208 KB
testcase_14 AC 224 ms
60,292 KB
testcase_15 AC 227 ms
60,644 KB
testcase_16 AC 229 ms
60,836 KB
testcase_17 AC 254 ms
61,468 KB
testcase_18 AC 235 ms
61,368 KB
testcase_19 AC 242 ms
61,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    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];
    int[] d = new int[K];
    for(int i = 0; i < M; i++) {
      a[i] = sc.nextInt() - 1;
      b[i] = sc.nextInt() - 1;
      c[i] = sc.nextInt();
    }
    for(int i = 0; i < K; i++) {
      d[i] = sc.nextInt();
    }
    // dp[i][j]はd1~di(i個)までから町jが可能性があるかどうかを表す
    int[][] dp = new int[K + 1][N];
    for(int j = 0; j < N; j++) {
      dp[0][j] = 1;
    }
    for(int i = 1; i < K + 1; i++) {
      for(int k = 0; k < M; k++) {
        if(c[k] == d[i - 1]) {
          int towna = a[k];
          int townb = b[k];
          if(dp[i][towna] == 0) {
            dp[i][towna] = dp[i - 1][townb];
          }
          if(dp[i][townb] == 0) {
            dp[i][townb] = dp[i - 1][towna];
          }
        }
      }
    }
    int ans = 0;
    for(int j = 0; j < N; j++) {
      ans += dp[K][j];
    }
    System.out.println(ans);
    ArrayList<Integer> town = new ArrayList<Integer>();
    for(int j = 0; j < N; j++) {
      if(dp[K][j] == 1) town.add(j + 1);
    }
    for(int j = 0; j < town.size(); j++) {
      System.out.print(town.get(j));
      if(j < town.size() - 1) {
        System.out.print(" ");
      } else {
        System.out.println();
      }
    }
  }
}
0