結果
問題 | No.2418 情報通だよ!Nafmoくん |
ユーザー | rlangevin |
提出日時 | 2023-09-03 15:10:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 306 ms / 2,000 ms |
コード長 | 1,179 bytes |
コンパイル時間 | 265 ms |
コンパイル使用メモリ | 87,008 KB |
実行使用メモリ | 106,648 KB |
最終ジャッジ日時 | 2023-09-03 15:10:08 |
合計ジャッジ時間 | 7,142 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
71,088 KB |
testcase_01 | AC | 76 ms
71,292 KB |
testcase_02 | AC | 70 ms
71,196 KB |
testcase_03 | AC | 249 ms
98,284 KB |
testcase_04 | AC | 139 ms
101,540 KB |
testcase_05 | AC | 263 ms
82,748 KB |
testcase_06 | AC | 202 ms
99,004 KB |
testcase_07 | AC | 274 ms
81,544 KB |
testcase_08 | AC | 209 ms
106,648 KB |
testcase_09 | AC | 280 ms
83,876 KB |
testcase_10 | AC | 271 ms
96,484 KB |
testcase_11 | AC | 238 ms
94,268 KB |
testcase_12 | AC | 215 ms
93,196 KB |
testcase_13 | AC | 185 ms
82,368 KB |
testcase_14 | AC | 214 ms
87,832 KB |
testcase_15 | AC | 141 ms
78,664 KB |
testcase_16 | AC | 306 ms
88,468 KB |
testcase_17 | AC | 158 ms
78,812 KB |
testcase_18 | AC | 195 ms
96,368 KB |
testcase_19 | AC | 126 ms
98,524 KB |
testcase_20 | AC | 148 ms
79,392 KB |
testcase_21 | AC | 183 ms
83,720 KB |
testcase_22 | AC | 203 ms
79,664 KB |
ソースコード
class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] N, M = map(int, input().split()) A, B = [0] * M, [0] * M U = UnionFind(2 * N) for i in range(M): A[i], B[i] = map(int, input().split()) A[i], B[i] = A[i] - 1, B[i] - 1 U.union(A[i], B[i]) S = set() ans = 0 for i in range(2 * N): v = U.find(i) if v in S: continue S.add(v) ans += U.get_size(i) % 2 print(ans // 2)