結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー pありpあり
提出日時 2023-08-12 13:51:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 94,976 KB
最終ジャッジ日時 2024-04-30 04:16:52
合計ジャッジ時間 5,555 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,504 KB
testcase_01 AC 46 ms
53,632 KB
testcase_02 AC 46 ms
53,760 KB
testcase_03 AC 309 ms
94,976 KB
testcase_04 AC 166 ms
86,144 KB
testcase_05 AC 215 ms
85,376 KB
testcase_06 AC 244 ms
91,776 KB
testcase_07 AC 208 ms
84,224 KB
testcase_08 AC 262 ms
94,208 KB
testcase_09 AC 257 ms
87,808 KB
testcase_10 AC 299 ms
93,952 KB
testcase_11 AC 266 ms
91,904 KB
testcase_12 AC 227 ms
88,832 KB
testcase_13 AC 160 ms
82,048 KB
testcase_14 AC 210 ms
86,272 KB
testcase_15 AC 150 ms
78,976 KB
testcase_16 AC 291 ms
90,880 KB
testcase_17 AC 132 ms
78,976 KB
testcase_18 AC 224 ms
89,088 KB
testcase_19 AC 151 ms
84,864 KB
testcase_20 AC 159 ms
79,232 KB
testcase_21 AC 171 ms
83,200 KB
testcase_22 AC 154 ms
80,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,m = map(int, input().split())

g = [[] for _ in range(2*n)]

for _ in range(m):
  a,b = map(int, input().split())
  a,b = a-1,b-1
  g[a].append(b)
  g[b].append(a)
  
c = [-1 for _ in range(2*n)]
cnow = 0
for i in range(2*n):
  if(c[i]!=-1):
    continue
    
  c[i] = cnow
  d = deque([i])
  while(d):
    now = d.pop()
    for v in g[now]:
      if(c[v]==-1):
        d.append(v)
        c[v] = cnow
  cnow+=1
  
count = [0 for _ in range(cnow)]
for i in c:
  count[i]+=1
  
for i in range(cnow):
  count[i]%=2
  
ans = sum(count)//2
print(ans)
    
  
  
  
  
  

0