結果

問題 No.1805 Approaching Many Typhoon
ユーザー ripityripity
提出日時 2022-03-16 22:34:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 2,836 ms
コンパイル使用メモリ 79,504 KB
実行使用メモリ 60,588 KB
最終ジャッジ日時 2023-10-25 06:10:33
合計ジャッジ時間 10,861 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
57,516 KB
testcase_01 AC 137 ms
57,564 KB
testcase_02 AC 136 ms
57,592 KB
testcase_03 AC 136 ms
57,568 KB
testcase_04 AC 135 ms
57,612 KB
testcase_05 AC 136 ms
57,512 KB
testcase_06 AC 137 ms
57,580 KB
testcase_07 AC 137 ms
57,740 KB
testcase_08 AC 136 ms
57,604 KB
testcase_09 AC 137 ms
57,516 KB
testcase_10 AC 138 ms
57,516 KB
testcase_11 AC 133 ms
57,288 KB
testcase_12 AC 133 ms
57,384 KB
testcase_13 AC 136 ms
57,676 KB
testcase_14 AC 138 ms
57,512 KB
testcase_15 AC 137 ms
57,600 KB
testcase_16 AC 136 ms
57,532 KB
testcase_17 AC 141 ms
57,572 KB
testcase_18 AC 140 ms
57,604 KB
testcase_19 AC 136 ms
57,492 KB
testcase_20 AC 135 ms
57,692 KB
testcase_21 AC 139 ms
57,500 KB
testcase_22 AC 141 ms
57,532 KB
testcase_23 AC 137 ms
57,548 KB
testcase_24 AC 124 ms
56,256 KB
testcase_25 AC 135 ms
57,524 KB
testcase_26 AC 135 ms
57,636 KB
testcase_27 AC 137 ms
57,472 KB
testcase_28 AC 217 ms
60,324 KB
testcase_29 AC 214 ms
60,044 KB
testcase_30 AC 217 ms
60,008 KB
testcase_31 AC 228 ms
60,588 KB
testcase_32 AC 161 ms
58,040 KB
testcase_33 AC 162 ms
57,916 KB
testcase_34 AC 190 ms
57,748 KB
testcase_35 AC 210 ms
59,816 KB
testcase_36 AC 211 ms
60,036 KB
testcase_37 AC 133 ms
57,328 KB
testcase_38 AC 136 ms
57,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    
    public static Scanner sc = new Scanner(System.in);
    public static PrintWriter pw = new PrintWriter(System.out);
    
    public static void main(String[] args) {
        
        int t = 1;
        while( t > 0 ) {
            solve();
            t--;
        }
        
        pw.flush();
        
    }
    
    static void solve() {
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int S = sc.nextInt()-1;
        int G = sc.nextInt()-1;
        boolean[] visited = new boolean[N];
        ArrayList<ArrayList<Integer>> edge = new ArrayList<>();
        LinkedList<Integer> que = new LinkedList<>();
        
        for( int i = 0; i < N; i++ ) {
            edge.add(new ArrayList<>());
        }
        
        for( int i = 0; i < M; i++ ) {
            int f = sc.nextInt()-1;
            int t = sc.nextInt()-1;
            edge.get(f).add(t);
            edge.get(t).add(f);
        }
        
        int U = sc.nextInt();
        for( int i = 0; i < U; i++ ) {
            int x = sc.nextInt()-1;
            visited[x] = true;
        }
        
        que.offer(S);
        while( !que.isEmpty() ) {
            int now = que.poll();
            if( visited[now] ) continue;
            visited[now] = true;
            for( int next : edge.get(now) ) {
                if( !visited[next] ) que.offer(next);
            }
        }
        
        pw.println( visited[G] ? "Yes" : "No" );
        
    }
    
}
0