結果

問題 No.1805 Approaching Many Typhoon
ユーザー tentententen
提出日時 2022-09-28 09:50:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 2,035 bytes
コンパイル時間 2,269 ms
コンパイル使用メモリ 74,912 KB
実行使用メモリ 53,676 KB
最終ジャッジ日時 2023-08-24 04:17:47
合計ジャッジ時間 6,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
49,528 KB
testcase_01 AC 48 ms
49,652 KB
testcase_02 AC 48 ms
48,092 KB
testcase_03 AC 49 ms
49,620 KB
testcase_04 AC 49 ms
49,804 KB
testcase_05 AC 49 ms
47,528 KB
testcase_06 AC 48 ms
49,892 KB
testcase_07 AC 48 ms
49,672 KB
testcase_08 AC 50 ms
49,508 KB
testcase_09 AC 49 ms
47,736 KB
testcase_10 AC 49 ms
49,608 KB
testcase_11 AC 48 ms
49,608 KB
testcase_12 AC 47 ms
49,892 KB
testcase_13 AC 50 ms
49,800 KB
testcase_14 AC 50 ms
49,856 KB
testcase_15 AC 51 ms
50,044 KB
testcase_16 AC 48 ms
49,512 KB
testcase_17 AC 50 ms
49,532 KB
testcase_18 AC 48 ms
49,900 KB
testcase_19 AC 50 ms
50,468 KB
testcase_20 AC 50 ms
49,504 KB
testcase_21 AC 48 ms
49,616 KB
testcase_22 AC 50 ms
49,740 KB
testcase_23 AC 50 ms
49,772 KB
testcase_24 AC 50 ms
49,528 KB
testcase_25 AC 51 ms
49,672 KB
testcase_26 AC 50 ms
49,892 KB
testcase_27 AC 50 ms
49,604 KB
testcase_28 AC 84 ms
51,044 KB
testcase_29 AC 89 ms
53,676 KB
testcase_30 AC 88 ms
51,816 KB
testcase_31 AC 89 ms
52,144 KB
testcase_32 AC 52 ms
50,564 KB
testcase_33 AC 54 ms
49,692 KB
testcase_34 AC 60 ms
50,452 KB
testcase_35 AC 74 ms
50,552 KB
testcase_36 AC 79 ms
50,760 KB
testcase_37 AC 48 ms
49,788 KB
testcase_38 AC 50 ms
49,896 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 s = sc.nextInt() - 1;
        int g = sc.nextInt() - 1;
        ArrayList<ArrayList<Integer>> 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;
            graph.get(a).add(b);
            graph.get(b).add(a);
        }
        HashSet<Integer> errors = new HashSet<>();
        int u = sc.nextInt();
        for (int i = 0; i < u; i++) {
            errors.add(sc.nextInt() - 1);
        }
        ArrayDeque<Integer> deq = new ArrayDeque<>();
        boolean[] visited = new boolean[n];
        deq.add(s);
        while (deq.size() > 0) {
            int x = deq.poll();
            if (visited[x] || errors.contains(x)) {
                continue;
            }
            visited[x] = true;
            deq.addAll(graph.get(x));
        }
        if (visited[g]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}
    
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