結果
問題 | No.2418 情報通だよ!Nafmoくん |
ユーザー | kemuniku |
提出日時 | 2023-08-12 13:43:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 257 ms / 2,000 ms |
コード長 | 930 bytes |
コンパイル時間 | 300 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 79,984 KB |
最終ジャッジ日時 | 2024-04-30 03:55:47 |
合計ジャッジ時間 | 4,959 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,352 KB |
testcase_01 | AC | 39 ms
52,480 KB |
testcase_02 | AC | 41 ms
52,352 KB |
testcase_03 | AC | 189 ms
79,488 KB |
testcase_04 | AC | 93 ms
78,720 KB |
testcase_05 | AC | 228 ms
78,196 KB |
testcase_06 | AC | 152 ms
79,616 KB |
testcase_07 | AC | 216 ms
77,696 KB |
testcase_08 | AC | 150 ms
79,984 KB |
testcase_09 | AC | 244 ms
78,592 KB |
testcase_10 | AC | 209 ms
79,592 KB |
testcase_11 | AC | 181 ms
79,104 KB |
testcase_12 | AC | 151 ms
78,408 KB |
testcase_13 | AC | 148 ms
77,824 KB |
testcase_14 | AC | 170 ms
78,372 KB |
testcase_15 | AC | 118 ms
76,144 KB |
testcase_16 | AC | 257 ms
79,040 KB |
testcase_17 | AC | 132 ms
76,416 KB |
testcase_18 | AC | 142 ms
78,976 KB |
testcase_19 | AC | 80 ms
76,416 KB |
testcase_20 | AC | 128 ms
76,368 KB |
testcase_21 | AC | 159 ms
77,808 KB |
testcase_22 | AC | 167 ms
77,056 KB |
ソースコード
N,M = map(int,input().split()) class UnionFind(): def __init__(self, n): self.count = n self.par = [-1]*n self.siz = [1]*n def root(self,x): if(self.par[x] == -1): return x else: self.par[x] = self.root(self.par[x]) return self.par[x] def issame(self,x,y): return self.root(x) == self.root(y) def unite(self,x,y): x = self.root(x) y = self.root(y) if(x == y): return False if(self.siz[x]<self.siz[y]): x,y = y,x self.par[y] = x self.siz[x] += self.siz[y] self.count -= 1 return True def size(self,x): return self.siz[self.root(x)] uf = UnionFind(2*N) for i in range(M): A,B = map(int,input().split()) uf.unite(A-1,B-1) amari = 0 for i in range(2*N): if uf.root(i) == i: siz = uf.siz[i] amari += siz%2 print(amari//2)