結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー kou_kkkkou_kkk
提出日時 2023-08-31 02:08:57
言語 Nim
(2.0.2)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 6,171 ms
コンパイル使用メモリ 68,920 KB
実行使用メモリ 16,016 KB
最終ジャッジ日時 2023-08-31 02:09:07
合計ジャッジ時間 9,065 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 68 ms
16,016 KB
testcase_04 AC 13 ms
10,120 KB
testcase_05 AC 47 ms
9,812 KB
testcase_06 AC 46 ms
13,736 KB
testcase_07 AC 53 ms
9,996 KB
testcase_08 AC 45 ms
14,808 KB
testcase_09 AC 64 ms
11,808 KB
testcase_10 AC 71 ms
14,696 KB
testcase_11 AC 57 ms
13,688 KB
testcase_12 AC 40 ms
11,316 KB
testcase_13 AC 19 ms
6,116 KB
testcase_14 AC 37 ms
9,768 KB
testcase_15 AC 48 ms
9,204 KB
testcase_16 AC 81 ms
14,228 KB
testcase_17 AC 21 ms
5,216 KB
testcase_18 AC 34 ms
11,208 KB
testcase_19 AC 11 ms
9,412 KB
testcase_20 AC 51 ms
9,036 KB
testcase_21 AC 22 ms
7,336 KB
testcase_22 AC 26 ms
6,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils, strutils

proc root(x: int, p: var seq[int]): int =
  if p[x] == -1: x
  else:
    p[x] = root(p[x], p)
    return p[x]

proc unite(x, y: int; p, rank, size: var seq[int]) =
  var
    rx = root(x, p)
    ry = root(y, p)
  if rank[rx] < rank[ry]: swap(rx, ry)
  p[ry] = rx
  if rank[rx] == rank[ry]: inc rank[rx]
  size[rx].inc size[ry]

var n, m: int
(n, m) = stdin.readLine.split.map parseInt
let ab = m.newSeqWith stdin.readLine.split.map parseInt

var
  p = (-1).repeat n * 2
  rank, size = 1.repeat n * 2

for v in ab:
  var
    a = pred v[0]
    b = pred v[1]
    ra = root(a, p)
    rb = root(b, p)
  if ra != rb: unite(a, b, p, rank, size)

var list: seq[int]
for i, v in p:
  if v == -1:
    list.add i

var cnt = 0
for idx in list:
  if size[idx] mod 2 == 1:
    inc cnt

echo cnt div 2
0