結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー titiatitia
提出日時 2023-08-17 00:37:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 738 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 20,224 KB
最終ジャッジ日時 2024-05-04 07:56:51
合計ジャッジ時間 7,681 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,880 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 27 ms
10,752 KB
testcase_03 AC 498 ms
19,456 KB
testcase_04 AC 126 ms
17,536 KB
testcase_05 AC 324 ms
14,208 KB
testcase_06 AC 307 ms
18,560 KB
testcase_07 AC 307 ms
13,568 KB
testcase_08 AC 317 ms
20,224 KB
testcase_09 AC 408 ms
15,232 KB
testcase_10 AC 456 ms
18,816 KB
testcase_11 AC 388 ms
18,176 KB
testcase_12 AC 279 ms
16,768 KB
testcase_13 AC 149 ms
13,184 KB
testcase_14 AC 261 ms
15,232 KB
testcase_15 AC 270 ms
11,008 KB
testcase_16 AC 468 ms
16,896 KB
testcase_17 AC 141 ms
11,264 KB
testcase_18 AC 252 ms
17,408 KB
testcase_19 AC 91 ms
17,024 KB
testcase_20 AC 284 ms
10,880 KB
testcase_21 AC 163 ms
13,824 KB
testcase_22 AC 169 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())

# UnionFind

Group = [i for i in range(2*N+1)] # グループ分け
Nodes = [1]*(2*N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

for i in range(M):
    a,b=map(int,input().split())
    Union(a,b)

ANS=0

for i in range(1,2*N+1):
    if find(i)==i:
        ANS+=Nodes[i]%2

print(ANS//2)
0