結果

問題 No.2072 Anatomy
コンテスト
ユーザー ntuda
提出日時 2022-09-18 22:15:16
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 599 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 120 ms
コンパイル使用メモリ 85,276 KB
実行使用メモリ 105,600 KB
最終ジャッジ日時 2026-05-28 12:12:55
合計ジャッジ時間 6,231 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(200050)

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

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

def size(x):
    x = root(x)
    return -P[x]

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