結果

問題 No.92 逃走経路
ユーザー uafr_csuafr_cs
提出日時 2015-06-17 02:49:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 601 ms / 5,000 ms
コード長 1,643 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 75,972 KB
実行使用メモリ 63,492 KB
最終ジャッジ日時 2023-09-21 09:14:20
合計ジャッジ時間 10,972 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 524 ms
63,492 KB
testcase_01 AC 127 ms
55,900 KB
testcase_02 AC 127 ms
55,920 KB
testcase_03 AC 127 ms
56,092 KB
testcase_04 AC 129 ms
55,900 KB
testcase_05 AC 409 ms
62,860 KB
testcase_06 AC 369 ms
62,688 KB
testcase_07 AC 379 ms
62,120 KB
testcase_08 AC 222 ms
59,336 KB
testcase_09 AC 327 ms
62,408 KB
testcase_10 AC 574 ms
62,932 KB
testcase_11 AC 601 ms
63,444 KB
testcase_12 AC 515 ms
62,920 KB
testcase_13 AC 299 ms
62,108 KB
testcase_14 AC 342 ms
61,748 KB
testcase_15 AC 413 ms
63,308 KB
testcase_16 AC 427 ms
62,920 KB
testcase_17 AC 505 ms
63,196 KB
testcase_18 AC 481 ms
63,280 KB
testcase_19 AC 409 ms
62,568 KB
権限があれば一括ダウンロードができます

ソースコード

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>();
			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);
						}
					}
				}
			}
			
			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