結果

問題 No.2072 Anatomy
ユーザー ntudantuda
提出日時 2022-09-18 22:23:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 488 ms / 2,000 ms
コード長 438 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 86,796 KB
実行使用メモリ 102,572 KB
最終ジャッジ日時 2023-08-23 18:21:36
合計ジャッジ時間 9,735 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,316 KB
testcase_01 AC 71 ms
71,196 KB
testcase_02 AC 73 ms
71,484 KB
testcase_03 AC 75 ms
71,312 KB
testcase_04 AC 72 ms
71,524 KB
testcase_05 AC 74 ms
71,544 KB
testcase_06 AC 74 ms
71,312 KB
testcase_07 AC 75 ms
71,532 KB
testcase_08 AC 488 ms
99,732 KB
testcase_09 AC 260 ms
98,764 KB
testcase_10 AC 429 ms
100,152 KB
testcase_11 AC 334 ms
99,676 KB
testcase_12 AC 301 ms
95,460 KB
testcase_13 AC 391 ms
101,156 KB
testcase_14 AC 380 ms
94,088 KB
testcase_15 AC 225 ms
90,720 KB
testcase_16 AC 416 ms
101,700 KB
testcase_17 AC 300 ms
99,732 KB
testcase_18 AC 213 ms
89,928 KB
testcase_19 AC 388 ms
101,620 KB
testcase_20 AC 484 ms
102,032 KB
testcase_21 AC 267 ms
98,708 KB
testcase_22 AC 412 ms
100,800 KB
testcase_23 AC 259 ms
99,016 KB
testcase_24 AC 260 ms
98,712 KB
testcase_25 AC 349 ms
100,948 KB
testcase_26 AC 65 ms
71,240 KB
testcase_27 AC 255 ms
98,664 KB
testcase_28 AC 380 ms
102,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def root(x):
    if P[x] < 0:
        return x
    else:
        P[x] = root(P[x])
        return P[x]
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        P[x] -= 1
        return
    if x > y: x,y = y,x
    P[x] = min(P[x], P[y]) - 1
    P[y] = x

N, M = map(int, input().split())
UV = [list(map(int, input().split())) for _ in range(M)]
P = [-1] * (N + 1)
for u, v in reversed(UV):
    unite(u, v)
print(- P[1] - 1)
0