結果

問題 No.92 逃走経路
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-28 06:26:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 288 ms / 5,000 ms
コード長 1,198 bytes
コンパイル時間 3,901 ms
コンパイル使用メモリ 79,392 KB
実行使用メモリ 48,932 KB
最終ジャッジ日時 2024-04-20 04:32:36
合計ジャッジ時間 8,857 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 266 ms
48,088 KB
testcase_01 AC 143 ms
42,380 KB
testcase_02 AC 133 ms
42,404 KB
testcase_03 AC 146 ms
42,404 KB
testcase_04 AC 134 ms
42,412 KB
testcase_05 AC 288 ms
48,116 KB
testcase_06 AC 247 ms
47,384 KB
testcase_07 AC 257 ms
47,296 KB
testcase_08 AC 202 ms
43,480 KB
testcase_09 AC 228 ms
44,992 KB
testcase_10 AC 285 ms
48,932 KB
testcase_11 AC 285 ms
47,988 KB
testcase_12 AC 288 ms
47,752 KB
testcase_13 AC 226 ms
44,936 KB
testcase_14 AC 226 ms
43,984 KB
testcase_15 AC 238 ms
44,536 KB
testcase_16 AC 254 ms
45,196 KB
testcase_17 AC 272 ms
48,080 KB
testcase_18 AC 260 ms
48,084 KB
testcase_19 AC 260 ms
48,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise134{
  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[][] r = new int[m][3];
    for(int i = 0; i < m; i++){
      r[i][0] = sc.nextInt();
      r[i][1] = sc.nextInt();
      r[i][2] = sc.nextInt();
    }
    int[] p = new int[k];
    for(int i = 0; i < k; i++){
      p[i] = sc.nextInt();
    }
    boolean[][] dp = new boolean[2][n + 1];
    for(int i = 0; i < m; i++){
      if(r[i][2] == p[0]){
        dp[0][r[i][0]] = true;
        dp[0][r[i][1]] = true;
      }
    }
    for(int i = 1; i < k; i++){
      Arrays.fill(dp[i % 2], false);
      for(int j = 0; j < m; j++){
        if(r[j][2] == p[i]){
          if(dp[(i - 1) % 2][r[j][0]]){
            dp[i % 2][r[j][1]] = true;
          }
          if(dp[(i - 1) % 2][r[j][1]]){
            dp[i % 2][r[j][0]] = true;
          }
        }
      }
    }
    int count = 0;
    String s = "";
    for(int i = 1; i < n + 1; i++){
      if(dp[(k - 1) % 2][i]){
        count++;
        s += i + " ";
      }
    }
    System.out.println(count);
    System.out.println(s);
  }
}
0