結果

問題 No.1805 Approaching Many Typhoon
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2022-01-15 01:38:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 82,468 KB
実行使用メモリ 70,096 KB
最終ジャッジ日時 2024-04-30 20:42:24
合計ジャッジ時間 3,083 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,540 KB
testcase_01 AC 34 ms
52,676 KB
testcase_02 AC 37 ms
53,012 KB
testcase_03 AC 33 ms
52,820 KB
testcase_04 AC 35 ms
52,280 KB
testcase_05 AC 36 ms
53,008 KB
testcase_06 AC 35 ms
53,484 KB
testcase_07 AC 33 ms
52,492 KB
testcase_08 AC 32 ms
52,784 KB
testcase_09 AC 34 ms
53,180 KB
testcase_10 AC 33 ms
53,948 KB
testcase_11 AC 33 ms
53,584 KB
testcase_12 AC 33 ms
53,216 KB
testcase_13 AC 33 ms
53,084 KB
testcase_14 AC 34 ms
54,264 KB
testcase_15 AC 34 ms
53,068 KB
testcase_16 AC 33 ms
53,544 KB
testcase_17 AC 33 ms
52,256 KB
testcase_18 AC 32 ms
52,404 KB
testcase_19 AC 33 ms
53,904 KB
testcase_20 AC 32 ms
53,000 KB
testcase_21 AC 32 ms
52,256 KB
testcase_22 AC 34 ms
52,332 KB
testcase_23 AC 33 ms
52,792 KB
testcase_24 AC 33 ms
53,160 KB
testcase_25 AC 34 ms
52,476 KB
testcase_26 AC 33 ms
53,272 KB
testcase_27 AC 32 ms
53,204 KB
testcase_28 AC 59 ms
69,564 KB
testcase_29 AC 58 ms
70,096 KB
testcase_30 AC 55 ms
69,316 KB
testcase_31 AC 56 ms
69,936 KB
testcase_32 AC 36 ms
54,344 KB
testcase_33 AC 34 ms
53,444 KB
testcase_34 AC 36 ms
54,380 KB
testcase_35 AC 41 ms
56,568 KB
testcase_36 AC 45 ms
62,332 KB
testcase_37 AC 33 ms
52,128 KB
testcase_38 AC 32 ms
52,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def uf_find(n,p):

    ufl = []

    while p[n] != n:
        ufl.append(n)
        n = p[n]

    for i in ufl:
        p[i] = n

    return n


def uf_union(a,b,p,rank):

    ap = uf_find(a,p)
    bp = uf_find(b,p)

    if ap == bp:
        return True
    else:

        if rank[ap] > rank[bp]:
            p[bp] = ap
        elif rank[ap] < rank[bp]:
            p[ap] = bp
        else:
            p[bp] = ap
            rank[ap] += 1

        return False

N,M = map(int,input().split())

S,G = map(int,input().split())
S -= 1; G -= 1

e = []
for i in range(M):
    F,T = map(int,input().split())
    F -= 1
    T -= 1
    e.append((F,T))

U = int(input())

I = [] if U == 0 else list(map(int,input().split()))
for i in range(len(I)):
    I[i] -= 1
s = set(I)

p = [i for i in range(N)]
rank = [0] * N
for u,v in e:
    if u not in s and v not in s:
        uf_union(u,v,p,rank)

if uf_find(S,p) == uf_find(G,p):
    print ("Yes")
else:
    print ("No")
0