結果

問題 No.1805 Approaching Many Typhoon
ユーザー ygd.ygd.
提出日時 2022-01-12 21:55:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 2,100 bytes
コンパイル時間 118 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-27 12:58:27
合計ジャッジ時間 2,201 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 28 ms
11,008 KB
testcase_02 AC 28 ms
11,008 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
11,008 KB
testcase_05 AC 31 ms
11,008 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 29 ms
11,008 KB
testcase_08 AC 28 ms
10,880 KB
testcase_09 AC 27 ms
10,880 KB
testcase_10 AC 27 ms
11,008 KB
testcase_11 AC 27 ms
11,008 KB
testcase_12 AC 26 ms
10,880 KB
testcase_13 AC 28 ms
10,880 KB
testcase_14 AC 29 ms
10,880 KB
testcase_15 AC 33 ms
10,880 KB
testcase_16 AC 29 ms
11,008 KB
testcase_17 AC 29 ms
11,008 KB
testcase_18 AC 30 ms
10,880 KB
testcase_19 AC 30 ms
11,008 KB
testcase_20 AC 29 ms
10,880 KB
testcase_21 AC 29 ms
10,880 KB
testcase_22 AC 29 ms
10,880 KB
testcase_23 AC 29 ms
10,880 KB
testcase_24 AC 28 ms
10,880 KB
testcase_25 AC 29 ms
11,008 KB
testcase_26 AC 29 ms
11,008 KB
testcase_27 AC 29 ms
10,880 KB
testcase_28 AC 33 ms
11,264 KB
testcase_29 AC 32 ms
11,264 KB
testcase_30 AC 33 ms
11,136 KB
testcase_31 AC 36 ms
11,136 KB
testcase_32 AC 29 ms
10,880 KB
testcase_33 AC 28 ms
11,008 KB
testcase_34 AC 29 ms
11,008 KB
testcase_35 AC 30 ms
11,136 KB
testcase_36 AC 34 ms
11,136 KB
testcase_37 AC 29 ms
11,008 KB
testcase_38 AC 29 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline #文字列につけてはダメ
#input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#MOD = pow(10,9) + 7
#MOD = 998244353


class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
    def find(self, x):
        """
        x が属するグループを探索して親を出す。
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]


def main():
    N,M = map(int,input().split())
    start,goal = map(int,input().split())
    start -= 1; goal -= 1
    Z = []
    for i in range(M):
        a,b = map(int,input().split())
        a -= 1; b -= 1
        Z.append((a,b))
    U = int(input())
    S = list(map(int,input().split()))
    S = [s-1 for s in S]
    S = set(S)
    uf = UnionFind(N)
    for a,b in Z:
        if a in S or b in S: continue
        uf.union(a,b)
    if uf.is_same(start,goal):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()
0