結果

問題 No.92 逃走経路
ユーザー holegumaholeguma
提出日時 2015-08-17 23:46:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 1,507 bytes
コンパイル時間 2,143 ms
コンパイル使用メモリ 79,972 KB
実行使用メモリ 54,832 KB
最終ジャッジ日時 2023-09-25 12:41:16
合計ジャッジ時間 5,312 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
54,792 KB
testcase_01 AC 43 ms
49,836 KB
testcase_02 AC 67 ms
51,080 KB
testcase_03 AC 67 ms
50,876 KB
testcase_04 AC 67 ms
50,992 KB
testcase_05 AC 143 ms
54,268 KB
testcase_06 AC 102 ms
51,216 KB
testcase_07 AC 102 ms
52,428 KB
testcase_08 AC 77 ms
51,940 KB
testcase_09 AC 97 ms
52,456 KB
testcase_10 AC 143 ms
54,268 KB
testcase_11 AC 145 ms
54,832 KB
testcase_12 AC 147 ms
54,804 KB
testcase_13 AC 94 ms
52,676 KB
testcase_14 AC 101 ms
52,956 KB
testcase_15 AC 106 ms
53,020 KB
testcase_16 AC 114 ms
52,056 KB
testcase_17 AC 137 ms
54,556 KB
testcase_18 AC 131 ms
53,816 KB
testcase_19 AC 124 ms
53,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);

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

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] values=br.readLine().split(" ");
int n=Integer.parseInt(values[0]);
int m=Integer.parseInt(values[1]);
int k=Integer.parseInt(values[2]);
ArrayList<Edge> array;
boolean[][] pos=new boolean[k][n+1];
int[] place=new int[n];
HashMap<Integer,ArrayList<Edge>> map=new HashMap<Integer,ArrayList<Edge>>();
for(int i=0;i<m;i++){
values=br.readLine().split(" ");
int a=Integer.parseInt(values[0]);
int b=Integer.parseInt(values[1]);
int c=Integer.parseInt(values[2]);
if(!map.containsKey(c)) array=new ArrayList<Edge>();
else array=map.get(c);
array.add(new Edge(a,b));
array.add(new Edge(b,a));
map.put(c,array);
}
StringTokenizer  st=new StringTokenizer(br.readLine());
for(int i=0;i<k;i++){
int d=Integer.parseInt(st.nextToken());
array=map.get(d);
for(int j=0;j<array.size();j++){
Edge e=array.get(j);
if(i==0) pos[0][e.to]=true;
else{
if(pos[i-1][e.from]) pos[i][e.to]=true;
}
}
}
int cnt=0;
for(int i=1;i<=n;i++){
if(pos[k-1][i]){
cnt++;
place[cnt-1]=i;
}
}
out.println(cnt);
for(int i=0;i<cnt;i++){
if(i==cnt-1) out.println(place[i]);
else out.print(place[i]+" ");
}
out.flush();
}
}
0