結果
| 問題 |
No.2418 情報通だよ!Nafmoくん
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2025-02-13 22:52:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 239 ms / 2,000 ms |
| コード長 | 584 bytes |
| コンパイル時間 | 756 ms |
| コンパイル使用メモリ | 82,112 KB |
| 実行使用メモリ | 101,160 KB |
| 最終ジャッジ日時 | 2025-02-13 22:52:23 |
| 合計ジャッジ時間 | 5,740 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
def root(x):
if P[x] < 0: return x
P[x] = root(P[x]) # 経路圧縮
return P[x]
def merge(x,y):
x = root(x)
y = root(y)
if x == y: return
if x > y: x,y = y,x
P[x] += P[y]
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())
P = [-1] * (N * 2)
for i in range(M):
a,b = map(int,input().split())
a -= 1
b -= 1
merge(a,b)
tmp = 0
S = set()
for i in range(2 * N):
if root(i) not in S:
tmp += size(i) % 2
S.add(root(i))
print(tmp//2)
ntuda