結果

問題 No.92 逃走経路
ユーザー uafr_csuafr_cs
提出日時 2015-06-17 02:27:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,674 bytes
コンパイル時間 3,844 ms
コンパイル使用メモリ 76,140 KB
実行使用メモリ 62,540 KB
最終ジャッジ日時 2023-09-21 09:13:54
合計ジャッジ時間 8,805 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 128 ms
55,884 KB
testcase_02 AC 128 ms
56,220 KB
testcase_03 AC 128 ms
55,808 KB
testcase_04 AC 127 ms
56,240 KB
testcase_05 AC 237 ms
59,616 KB
testcase_06 AC 328 ms
62,336 KB
testcase_07 AC 326 ms
62,540 KB
testcase_08 AC 220 ms
59,136 KB
testcase_09 AC 350 ms
60,896 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		final int K = sc.nextInt();
		
		ArrayList<LinkedHashMap<Integer, LinkedList<Long>>> adj = new ArrayList<LinkedHashMap<Integer, LinkedList<Long>>>();
		for(int i = 0; i < N; i++){
			adj.add(new LinkedHashMap<Integer, LinkedList<Long>>());
		}
		
		for(int i = 0; i < M; i++){
			final int a = sc.nextInt() - 1;
			final int b = sc.nextInt() - 1;
			final long c = sc.nextLong();
			
			if(!adj.get(a).containsKey(b)){
				adj.get(a).put(b, new LinkedList<Long>());
			}
			if(!adj.get(b).containsKey(a)){
				adj.get(b).put(a, new LinkedList<Long>());
			}
			
			adj.get(a).get(b).add(c);
			adj.get(b).get(a).add(c);
		}
		
		TreeSet<Integer> set = new TreeSet<Integer>();
		for(int i = 0; i < N; i++){ 
			set.add(i);
		}
		
		for(int i = 0; i < K; i++){
			final long d = sc.nextLong();
			
			TreeSet<Integer> new_set = new TreeSet<Integer>();
			LOOP:
			for(final int node : set){
				for(final int next : adj.get(node).keySet()){
					for(final long cost : adj.get(node).get(next)){
						if(cost == d){
							new_set.add(next);
							continue LOOP;
						}
					}
				}
			}
			
			set.clear();
			set.addAll(new_set);
		}
	
		System.out.println(set.size());
		boolean first = true;
		for(final int node : set){
			if(first){
				first = false;
			}else{
				System.out.print(" ");
			}
			System.out.print(node + 1);
		}
		System.out.println();
		
	}
}
0