結果

問題 No.92 逃走経路
ユーザー tentententen
提出日時 2022-10-13 12:59:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 274 ms / 5,000 ms
コード長 2,426 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 75,820 KB
実行使用メモリ 60,108 KB
最終ジャッジ日時 2023-09-08 19:04:08
合計ジャッジ時間 6,679 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
59,376 KB
testcase_01 AC 43 ms
49,504 KB
testcase_02 AC 44 ms
49,336 KB
testcase_03 AC 45 ms
49,380 KB
testcase_04 AC 43 ms
49,328 KB
testcase_05 AC 212 ms
57,524 KB
testcase_06 AC 184 ms
57,372 KB
testcase_07 AC 188 ms
57,080 KB
testcase_08 AC 63 ms
51,484 KB
testcase_09 AC 144 ms
56,324 KB
testcase_10 AC 258 ms
59,276 KB
testcase_11 AC 274 ms
60,108 KB
testcase_12 AC 266 ms
59,484 KB
testcase_13 AC 125 ms
56,144 KB
testcase_14 AC 148 ms
56,928 KB
testcase_15 AC 173 ms
56,900 KB
testcase_16 AC 170 ms
57,228 KB
testcase_17 AC 197 ms
59,084 KB
testcase_18 AC 186 ms
58,420 KB
testcase_19 AC 186 ms
55,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<ArrayList<Path>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt();
            graph.get(a).add(new Path(b, c));
            graph.get(b).add(new Path(a, c));
        }
        TreeSet<Integer> current = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            current.add(i);
        }
        for (int i = 0; i < k; i++) {
            TreeSet<Integer> next = new TreeSet<>();
            int d = sc.nextInt();
            for (int x : current) {
                for (Path y : graph.get(x)) {
                    if (y.value == d) {
                        next.add(y.idx);
                    }
                }
            }
            current = next;
        }
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (int x : current) {
            if (!isFirst) {
                sb.append(" ");
            }
            isFirst = false;
            sb.append(x + 1);
        }
        System.out.println(current.size());
        System.out.println(sb);
    }
    
    static class Path {
        int idx;
        int value;
        
        public Path (int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0