結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー ああいいああいい
提出日時 2023-08-12 18:44:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 560 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 78,408 KB
最終ジャッジ日時 2024-04-30 13:50:06
合計ジャッジ時間 4,345 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,360 KB
testcase_01 AC 41 ms
52,640 KB
testcase_02 AC 41 ms
52,992 KB
testcase_03 AC 169 ms
78,400 KB
testcase_04 AC 85 ms
77,268 KB
testcase_05 AC 182 ms
77,912 KB
testcase_06 AC 131 ms
78,176 KB
testcase_07 AC 178 ms
77,288 KB
testcase_08 AC 129 ms
77,972 KB
testcase_09 AC 202 ms
77,908 KB
testcase_10 AC 177 ms
78,104 KB
testcase_11 AC 160 ms
77,928 KB
testcase_12 AC 134 ms
77,484 KB
testcase_13 AC 123 ms
77,068 KB
testcase_14 AC 142 ms
77,160 KB
testcase_15 AC 112 ms
76,224 KB
testcase_16 AC 220 ms
78,408 KB
testcase_17 AC 122 ms
76,632 KB
testcase_18 AC 122 ms
77,488 KB
testcase_19 AC 75 ms
74,852 KB
testcase_20 AC 119 ms
76,480 KB
testcase_21 AC 122 ms
77,168 KB
testcase_22 AC 146 ms
76,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)

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

parent = [-1] * (N + N)
def find(i):
    if parent[i] < 0:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    if parent[I] < parent[J]:
        I,J =J,I
    parent[J] += parent[I]
    parent[I] = J
    return True

for _ in range(M):
    a,b = map(int,input().split())
    unite(a - 1,b - 1)

t = 0
for i in range(N + N):
    if parent[i] < 0:
        if -parent[i] % 2 == 1:t += 1
print(t // 2)
0