結果

問題 No.92 逃走経路
ユーザー ぴろずぴろず
提出日時 2014-12-07 19:40:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 317 ms / 5,000 ms
コード長 1,756 bytes
コンパイル時間 4,780 ms
コンパイル使用メモリ 76,080 KB
実行使用メモリ 61,208 KB
最終ジャッジ日時 2023-09-02 09:25:33
合計ジャッジ時間 11,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 297 ms
60,456 KB
testcase_01 AC 123 ms
56,208 KB
testcase_02 AC 123 ms
55,840 KB
testcase_03 AC 123 ms
56,000 KB
testcase_04 AC 125 ms
56,224 KB
testcase_05 AC 302 ms
60,212 KB
testcase_06 AC 303 ms
60,436 KB
testcase_07 AC 299 ms
60,376 KB
testcase_08 AC 190 ms
56,524 KB
testcase_09 AC 221 ms
61,208 KB
testcase_10 AC 313 ms
60,772 KB
testcase_11 AC 317 ms
60,416 KB
testcase_12 AC 297 ms
60,672 KB
testcase_13 AC 213 ms
59,292 KB
testcase_14 AC 223 ms
59,296 KB
testcase_15 AC 249 ms
59,944 KB
testcase_16 AC 253 ms
59,404 KB
testcase_17 AC 285 ms
58,052 KB
testcase_18 AC 294 ms
60,648 KB
testcase_19 AC 289 ms
60,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no092;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		Graph g = new Graph(n);
		for(int i=0;i<m;i++) {
			g.addBidirectionalEdge(sc.nextInt()-1, sc.nextInt()-1, sc.nextInt());
		}
		int[] d = new int[k];
		for(int i=0;i<k;i++) {
			d[i] = sc.nextInt();
		}
		boolean[][] dp = new boolean[k+1][n];
		Arrays.fill(dp[0], true);
		for(int i=0;i<k;i++) {
			for(int v=0;v<n;v++) {
				if (!dp[i][v]) {
					continue;
				}
				for(Graph.Edge e:g.graph[v]) {
					if (e.cost == d[i]) {
						dp[i+1][e.to] = true;
					}
				}
			}
		}
		ArrayList<Integer> ans = new ArrayList<>();
		for(int i=0;i<n;i++) {
			if (dp[k][i] == true) {
				ans.add(i+1);
			}
		}
		System.out.println(ans.size());
		for(int i=0;i<ans.size();i++) {
			if (i > 0) {
				System.out.print(" ");
			}
			System.out.print(ans.get(i));
		}
		System.out.println();
	}

}
class Graph {
	public static final int INF = 1<<29;
	int n;
	ArrayList<Edge>[] graph;

	@SuppressWarnings("unchecked")
	public Graph(int n) {
		this.n = n;
		this.graph = new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i] = new ArrayList<Edge>();
		}
	}

	public void addBidirectionalEdge(int from,int to,int cost) {
		addEdge(from,to,cost);
		addEdge(to,from,cost);
	}
	public void addEdge(int from,int to,int cost) {
		graph[from].add(new Edge(to, cost));
	}

	class Edge {
		int to;
		int cost;
		public Edge(int to,int cost) {
			this.to = to;
			this.cost = cost;
		}
	}

}
0