結果

問題 No.92 逃走経路
ユーザー holegumaholeguma
提出日時 2015-08-17 23:41:11
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,500 bytes
コンパイル時間 2,648 ms
コンパイル使用メモリ 83,508 KB
実行使用メモリ 54,216 KB
最終ジャッジ日時 2023-09-25 12:41:04
合計ジャッジ時間 4,961 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます

ソースコード

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];
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=0;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]);
out.print(place[i]+" ");
}
out.flush();
}
}
0