結果
問題 | No.92 逃走経路 |
ユーザー |
![]() |
提出日時 | 2015-06-17 02:49:38 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 580 ms / 5,000 ms |
コード長 | 1,643 bytes |
コンパイル時間 | 2,528 ms |
コンパイル使用メモリ | 80,204 KB |
実行使用メモリ | 61,960 KB |
最終ジャッジ日時 | 2024-07-07 03:28:07 |
合計ジャッジ時間 | 11,617 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
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();}}