結果

問題 No.92 逃走経路
ユーザー amyuamyu
提出日時 2016-06-17 20:22:25
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,759 bytes
コンパイル時間 2,925 ms
コンパイル使用メモリ 90,864 KB
実行使用メモリ 63,452 KB
最終ジャッジ日時 2024-04-17 23:15:02
合計ジャッジ時間 14,634 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main{
    static final Scanner sc = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    public static void main(String[] args){
    	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];
        for(int i=0;i<m;i++){
            a[i] = sc.nextInt()-1;
            b[i] = sc.nextInt()-1;
            c[i] = sc.nextInt();
        }
        int[] d = new int[k];
        for(int i=0;i<k;i++){
            d[i] = sc.nextInt();
        }
        ArrayList<Integer> list1 = new ArrayList<Integer>();
        ArrayList<Integer> list2 = new ArrayList<Integer>();
        for(int i=0;i<n;i++){
            list1.add(i);
        }
        int count = 0;
        while(count<k){
            for(int i=0;i<list1.size();i++){
                int x = list1.get(i);
                for(int j=0;j<m;j++){
                    if(a[j]==x && d[count]==c[j]){
                        list2.add(b[j]);
                    }
                    else if(b[j]==x && d[count]==c[j]){
                        list2.add(a[j]);
                    }
                }
            }
            list1.clear();
            for(int i=0;i<list2.size();i++){
                list1.add(list2.get(i));
            }
            list2.clear();
            count++;
        }
        out.println(list1.size());
        for(Iterator<Integer> iterator = list1.iterator();iterator.hasNext();){
            out.print((iterator.next()+1)+" ");
        }
        out.println();
        out.flush();
    }

    //static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

0