結果

問題 No.92 逃走経路
ユーザー GrenacheGrenache
提出日時 2015-11-23 14:04:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 430 ms / 5,000 ms
コード長 1,770 bytes
コンパイル時間 3,701 ms
コンパイル使用メモリ 76,448 KB
実行使用メモリ 61,716 KB
最終ジャッジ日時 2023-10-11 18:20:44
合計ジャッジ時間 11,019 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 378 ms
61,332 KB
testcase_01 AC 134 ms
55,744 KB
testcase_02 AC 131 ms
55,920 KB
testcase_03 AC 128 ms
56,232 KB
testcase_04 AC 129 ms
55,828 KB
testcase_05 AC 344 ms
61,172 KB
testcase_06 AC 341 ms
60,552 KB
testcase_07 AC 319 ms
60,836 KB
testcase_08 AC 202 ms
59,376 KB
testcase_09 AC 297 ms
60,092 KB
testcase_10 AC 403 ms
61,716 KB
testcase_11 AC 430 ms
61,208 KB
testcase_12 AC 425 ms
61,148 KB
testcase_13 AC 272 ms
59,716 KB
testcase_14 AC 288 ms
60,320 KB
testcase_15 AC 325 ms
60,432 KB
testcase_16 AC 313 ms
60,464 KB
testcase_17 AC 353 ms
61,340 KB
testcase_18 AC 346 ms
61,268 KB
testcase_19 AC 331 ms
61,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;


public class Main_yukicoder92 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        List<Queue<Edge>> edges = new ArrayList<Queue<Edge>>();
        for (int i = 0; i < n; i++) {
        	edges.add(new ArrayDeque<Edge>());
        }
        for (int i = 0; i < m; i++) {
        	int a = sc.nextInt() - 1;
        	int b = sc.nextInt() - 1;
        	int c = sc.nextInt();

        	edges.get(a).add(new Edge(a, b, c));
        	edges.get(b).add(new Edge(b, a, c));
        }

        int[] d = new int[k];
        for (int i = 0; i < k; i++) {
        	d[i] = sc.nextInt();
        }

    	Set<Integer> ret = new TreeSet<Integer>();
    	for (int i = 0; i < n; i++) {
    		ret.add(i);
    	}

    	for (int i = 0; i < k; i++) {
    		Set<Integer> tmp = new TreeSet<Integer>();
    		for (int v : ret) {
        		for (Edge e : edges.get(v)) {
        			if (e.w == d[i]) {
        				tmp.add(e.v);
        			}
        		}

    		}
    		ret = tmp;
    	}

        System.out.println(ret.size());
        boolean flag = false;
        for (int e : ret) {
        	if (!flag) {
        		System.out.printf("%d", e + 1);
        		flag = true;
        	} else {
        		System.out.printf(" %d", e + 1);
        	}
        }
        System.out.println("");

        sc.close();
    }

	private static class Edge {
//		int u; // from
		int v; // to
		int w; // cost

		Edge(int u, int v, int w) {
//			this.u = u;
			this.v = v;
			this.w = w;
		}
	}
}
0