結果
| 問題 |
No.2418 情報通だよ!Nafmoくん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-12 14:05:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 630 bytes |
| コンパイル時間 | 337 ms |
| コンパイル使用メモリ | 82,512 KB |
| 実行使用メモリ | 103,404 KB |
| 最終ジャッジ日時 | 2024-11-19 17:21:45 |
| 合計ジャッジ時間 | 5,349 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 20 |
ソースコード
from collections import Counter class UnionFind(): def __init__(self,n): self.parents = list(range(n)) def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): px = self.find(x) py = self.find(y) if px != py: self.parents[px] = py def main(): n,m=map(int,input().split()) uf = UnionFind(2*n+1) for i in range(m): a,b=map(int,input().split()) uf.union(a,b) c = Counter(uf.parents[1:]) ans = 0 for v in c.values(): if v % 2 == 1: ans += 1 print(ans//2) if __name__ == "__main__": main()