結果

問題 No.92 逃走経路
ユーザー GrenacheGrenache
提出日時 2015-11-23 11:47:36
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,159 bytes
コンパイル時間 4,407 ms
コンパイル使用メモリ 78,628 KB
実行使用メモリ 123,028 KB
最終ジャッジ日時 2023-10-11 18:19:45
合計ジャッジ時間 15,573 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 398 ms
62,236 KB
testcase_01 AC 126 ms
55,824 KB
testcase_02 AC 126 ms
55,848 KB
testcase_03 AC 127 ms
55,984 KB
testcase_04 AC 126 ms
55,836 KB
testcase_05 AC 795 ms
123,028 KB
testcase_06 AC 355 ms
61,832 KB
testcase_07 AC 339 ms
62,016 KB
testcase_08 AC 200 ms
56,340 KB
testcase_09 AC 290 ms
60,992 KB
testcase_10 AC 478 ms
68,860 KB
testcase_11 AC 459 ms
62,772 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
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++) {
        	Deque<Integer> sts = new ArrayDeque<Integer>();
        	Deque<Integer> std = new ArrayDeque<Integer>();
        	Deque<Integer> stn = new ArrayDeque<Integer>();
        	sts.push(i);
        	std.push(0);
        	stn.push(i);

        	while (!sts.isEmpty()) {
        		int st = sts.pop();
        		int di = std.pop();
        		int no = stn.pop();

        		if (di == k) {
        			ret.add(st);
        			break;
        		}

        		for (Edge e : edges.get(no)) {
        			if (e.w == d[k - 1 - di]) {
        				sts.push(st);
        				std.push(di + 1);
        				stn.push(e.v);
        			}
        		}
        	}
        }

        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