結果
問題 | No.2418 情報通だよ!Nafmoくん |
ユーザー | sepa38 |
提出日時 | 2023-07-15 14:07:29 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 620 ms / 2,000 ms |
コード長 | 730 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 20,096 KB |
最終ジャッジ日時 | 2024-04-30 02:52:13 |
合計ジャッジ時間 | 8,750 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 30 ms
10,624 KB |
testcase_02 | AC | 31 ms
10,624 KB |
testcase_03 | AC | 620 ms
19,584 KB |
testcase_04 | AC | 178 ms
17,664 KB |
testcase_05 | AC | 400 ms
14,208 KB |
testcase_06 | AC | 413 ms
18,688 KB |
testcase_07 | AC | 428 ms
13,568 KB |
testcase_08 | AC | 442 ms
20,096 KB |
testcase_09 | AC | 529 ms
15,232 KB |
testcase_10 | AC | 616 ms
18,688 KB |
testcase_11 | AC | 511 ms
18,176 KB |
testcase_12 | AC | 354 ms
16,640 KB |
testcase_13 | AC | 187 ms
13,184 KB |
testcase_14 | AC | 333 ms
15,104 KB |
testcase_15 | AC | 353 ms
10,880 KB |
testcase_16 | AC | 603 ms
16,896 KB |
testcase_17 | AC | 198 ms
11,264 KB |
testcase_18 | AC | 351 ms
17,280 KB |
testcase_19 | AC | 136 ms
16,896 KB |
testcase_20 | AC | 384 ms
10,880 KB |
testcase_21 | AC | 226 ms
13,952 KB |
testcase_22 | AC | 224 ms
12,032 KB |
ソースコード
import sys sys.setrecursionlimit(500000) class UF: def __init__(self, n): self.root = [i for i in range(n)] self.subt = [1] * n def find(self, x): if self.root[x] == x: return x else: self.root[x] = self.find(self.root[x]) return self.root[x] def union(self, x, y): x, y = self.find(x), self.find(y) x, y = min(x, y), max(x, y) if x != y: self.subt[x] += self.subt[y] self.root[y] = x def size(self, x): return self.subt[self.find(x)] n, m = map(int, input().split()) uf = UF(n*2) for _ in range(m): a, b = map(lambda x: int(x)-1, input().split()) uf.union(a, b) ans = 0 for i in range(n*2): ans += (uf.find(i) == i) * (uf.size(i) % 2) print(ans // 2)