結果
問題 |
No.1805 Approaching Many Typhoon
|
ユーザー |
![]() |
提出日時 | 2022-03-16 22:34:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 218 ms / 2,000 ms |
コード長 | 1,528 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 79,804 KB |
実行使用メモリ | 57,760 KB |
最終ジャッジ日時 | 2024-09-25 01:35:03 |
合計ジャッジ時間 | 9,048 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
ソースコード
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" ); } }