結果

問題 No.92 逃走経路
ユーザー fal_rnd
提出日時 2017-01-20 17:52:48
言語 Java
(openjdk 23)
結果
AC  
実行時間 332 ms / 5,000 ms
コード長 1,135 bytes
コンパイル時間 4,149 ms
コンパイル使用メモリ 80,328 KB
実行使用メモリ 47,132 KB
最終ジャッジ日時 2024-12-23 02:52:51
合計ジャッジ時間 9,565 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

package src;

import java.util.*;
public class A{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int n=s.nextInt()+1,m=s.nextInt(),k=s.nextInt();
		BitSet[] dp = new BitSet[k+1];
						{
							for(int i=0;i<dp.length;i++) dp[i] = new BitSet(n);
							dp[0].set(1,n);
						}
		Way[] way =new Way[m*2];
						{
							int a,b,c;
							for(int i=0;i<m;i++) {
								a=s.nextInt();
								b=s.nextInt();
								c=s.nextInt();
								way[i*2  ]=new Way(a, b, c);
								way[i*2+1]=new Way(b, a, c);
							}
						}
		int[] pay = new int[k];
						{
							for(int i=0;i<k;i++) pay[i]=s.nextInt();
							Arrays.sort(way, (o1,o2)->o1.c-o2.c);
						}
		for(int i=0;i<k;i++) {
			int p=pay[i];
			for(Way w:way) {
				if(w.c==p && dp[i].get(w.a)) {
					dp[i+1].set(w.b);
				}
			}
		}
		System.out.println(dp[k].cardinality());
		System.out.println(dp[k].toString().replaceAll("[^0-9,]", "").replaceAll(",", " "));
		/*
		System.out.println();
		for(int i=0;i<k;i++) System.out.println(dp[i].toString());
		*/
	}
}
class Way{
	int a,b,c;
	Way(int p,int q,int r) {
		a=p;
		b=q;
		c=r;
	}
}
0