結果

問題 No.92 逃走経路
ユーザー tetsutetsu
提出日時 2018-02-19 23:58:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 149 ms / 5,000 ms
コード長 2,280 bytes
コンパイル時間 4,078 ms
コンパイル使用メモリ 77,396 KB
実行使用メモリ 56,616 KB
最終ジャッジ日時 2023-09-23 03:42:17
合計ジャッジ時間 7,486 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
56,436 KB
testcase_01 AC 45 ms
49,524 KB
testcase_02 AC 53 ms
49,596 KB
testcase_03 AC 53 ms
49,744 KB
testcase_04 AC 53 ms
49,800 KB
testcase_05 AC 139 ms
54,324 KB
testcase_06 AC 134 ms
53,488 KB
testcase_07 AC 131 ms
53,712 KB
testcase_08 AC 66 ms
50,172 KB
testcase_09 AC 102 ms
55,236 KB
testcase_10 AC 130 ms
53,936 KB
testcase_11 AC 130 ms
56,020 KB
testcase_12 AC 137 ms
56,180 KB
testcase_13 AC 116 ms
55,940 KB
testcase_14 AC 109 ms
55,248 KB
testcase_15 AC 138 ms
56,148 KB
testcase_16 AC 141 ms
56,616 KB
testcase_17 AC 145 ms
56,380 KB
testcase_18 AC 144 ms
53,800 KB
testcase_19 AC 134 ms
53,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class P92 {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		final int n = sc.nextInt(); final int m = sc.nextInt(); final int k = sc.nextInt();
		HashMap<Integer, ArrayList<Edge>> adj = new HashMap<>(n+1);
		for(int i=1; i<=n; i++) {
			adj.put(i, new ArrayList<Edge>());
		}
		for(int i=0; i<m; i++) {
			int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt();
			adj.get(a).add(new Edge(b, c));
			adj.get(b).add(new Edge(a, c));
		}
		int[] ds = new int[k+1];
		for(int i=1; i<=k; i++) {
			ds[i] = sc.nextInt();
		}
		boolean[][] exists = new boolean[k+1][n+1];
		Arrays.fill(exists[0], true);
		for(int t=1; t<=k; t++) {
			for(int i=1; i<=n; i++) {
				if(exists[t-1][i]) {
					for(Edge e : adj.get(i)) {
						if(ds[t] == e.w) {
							exists[t][e.to] = true;
						}
					}
				}
			}
		}
		int cnt = 0;
		ArrayList<Integer> ans = new ArrayList<>();
		for(int i=1; i<=n; i++) {
			if(exists[k][i]) {
				cnt++;
				ans.add(i);
			}
		}
		pw.println(cnt);
		for(int i=0; i<cnt; i++) {
			if(i==0) {
				pw.print(ans.get(i));
			} else {
				pw.print(" " + ans.get(i));
			}
		}
		pw.println();
		pw.close();
	}
	
	static class Edge {
		int to;
		int w;
		Edge(int _to, int _w) {
			to = _to; w = _w;
		}
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}
0