結果

問題 No.2202 贅沢てりたまチキン
ユーザー ntudantuda
提出日時 2023-02-05 22:07:56
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 802 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 108,396 KB
最終ジャッジ日時 2023-09-17 11:56:33
合計ジャッジ時間 7,789 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,144 KB
testcase_01 AC 72 ms
71,200 KB
testcase_02 AC 73 ms
71,400 KB
testcase_03 AC 73 ms
71,268 KB
testcase_04 AC 72 ms
71,084 KB
testcase_05 AC 74 ms
70,888 KB
testcase_06 AC 75 ms
71,056 KB
testcase_07 AC 72 ms
70,840 KB
testcase_08 AC 73 ms
71,432 KB
testcase_09 AC 74 ms
71,152 KB
testcase_10 AC 77 ms
78,096 KB
testcase_11 AC 73 ms
70,844 KB
testcase_12 AC 73 ms
71,080 KB
testcase_13 AC 73 ms
71,088 KB
testcase_14 AC 264 ms
100,288 KB
testcase_15 AC 261 ms
100,272 KB
testcase_16 AC 259 ms
100,528 KB
testcase_17 AC 267 ms
100,564 KB
testcase_18 AC 188 ms
92,488 KB
testcase_19 AC 184 ms
90,744 KB
testcase_20 AC 290 ms
101,372 KB
testcase_21 AC 284 ms
101,668 KB
testcase_22 AC 262 ms
97,252 KB
testcase_23 AC 411 ms
101,112 KB
testcase_24 AC 342 ms
99,040 KB
testcase_25 AC 802 ms
108,396 KB
testcase_26 AC 277 ms
101,776 KB
testcase_27 AC 273 ms
100,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def find(x):
    if P[x] == x:
        return x
    else:
        P[x] = find(P[x])  # 経路圧縮
        return P[x]

def same(x, y):
    return find(x) == find(y)

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y: return 0
    if x > y: x, y = y, x
    P[y] = x

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
P = [i for i in range(2 * (N + 1))]

for a, b in AB:
    unite(a, b + N)
    unite(a + N, b)

for i in range(1, N + 1):
    if not same(i, i + N):
        print("No")
        break
else:
    print("Yes")
0