結果

問題 No.92 逃走経路
ユーザー kou6839kou6839
提出日時 2014-12-21 12:24:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 380 ms / 5,000 ms
コード長 1,621 bytes
コンパイル時間 2,963 ms
コンパイル使用メモリ 76,772 KB
実行使用メモリ 62,408 KB
最終ジャッジ日時 2023-09-02 20:42:50
合計ジャッジ時間 9,432 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 319 ms
62,408 KB
testcase_01 AC 163 ms
56,544 KB
testcase_02 AC 167 ms
56,664 KB
testcase_03 AC 165 ms
56,488 KB
testcase_04 AC 164 ms
56,536 KB
testcase_05 AC 356 ms
60,220 KB
testcase_06 AC 327 ms
60,528 KB
testcase_07 AC 325 ms
60,712 KB
testcase_08 AC 225 ms
61,032 KB
testcase_09 AC 249 ms
60,016 KB
testcase_10 AC 361 ms
60,216 KB
testcase_11 AC 370 ms
60,616 KB
testcase_12 AC 380 ms
60,552 KB
testcase_13 AC 255 ms
61,892 KB
testcase_14 AC 263 ms
59,668 KB
testcase_15 AC 273 ms
59,056 KB
testcase_16 AC 284 ms
59,940 KB
testcase_17 AC 304 ms
61,872 KB
testcase_18 AC 316 ms
61,512 KB
testcase_19 AC 318 ms
61,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
class Pare{
	int to;
	int cost;
	Pare(int a,int b){
		to=a;
		cost=b;
	}
}
class Main{
	static void dfs(int nowc,int nowk,ArrayList<Pare>[] mati,int[] d,int[][] memo,boolean[] check){
		if(nowk==d.length){
			check[nowc]=true;
			return;
		}
		if(memo[nowc][nowk]==1) return;
		if(mati[nowc]==null) return;
		for(int b=0;b<mati[nowc].size();b++){
			if(mati[nowc].get(b).cost==d[nowk] ){
				memo[nowc][nowk]=1;
				dfs(mati[nowc].get(b).to,nowk+1,mati,d,memo,check);
			}
		}
		
	}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Pare>[] miti = new ArrayList[n];
        for(int i=0;i<m;i++){
        	int a = sc.nextInt()-1;
        	int b = sc.nextInt()-1;
        	int c = sc.nextInt();
        	if(miti[a]==null) miti[a]=new ArrayList<Pare>();
        	if(miti[b]==null) miti[b]=new ArrayList<Pare>();
        	miti[a].add(new Pare(b,c));
        	miti[b].add(new Pare(a,c));
        }
        int[] d = new int[k];
        for(int i=0;i<k;i++){
        	d[i]=sc.nextInt();
        }
        int[][] memo = new int[n][k];
        boolean[] check = new boolean[n];
        for(int i=0;i<n;i++){
        	dfs(i,0,miti,d,memo,check);
        }
        int ans=0;
        for(int i=0;i<n;i++){
        	if(check[i]) ans++;
        }
        System.out.println(ans);
        String aa ="";
        for(int i=0;i<n;i++){
        	if(check[i]) aa+=(i+1)+" ";
        }
        System.out.println(aa.trim());
        
        
    }
}
0