結果

問題 No.763 Noelちゃんと木遊び
ユーザー ikdikd
提出日時 2018-12-11 07:23:36
言語 Nim
(2.0.2)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 3,051 ms
コンパイル使用メモリ 68,948 KB
実行使用メモリ 17,196 KB
最終ジャッジ日時 2023-09-13 21:23:07
合計ジャッジ時間 5,594 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
17,196 KB
testcase_01 AC 32 ms
6,248 KB
testcase_02 AC 85 ms
11,572 KB
testcase_03 AC 54 ms
8,316 KB
testcase_04 AC 37 ms
6,780 KB
testcase_05 AC 52 ms
8,124 KB
testcase_06 AC 104 ms
13,248 KB
testcase_07 AC 103 ms
13,024 KB
testcase_08 AC 56 ms
8,680 KB
testcase_09 AC 35 ms
6,664 KB
testcase_10 AC 15 ms
4,480 KB
testcase_11 AC 104 ms
13,436 KB
testcase_12 AC 95 ms
12,200 KB
testcase_13 AC 93 ms
12,172 KB
testcase_14 AC 82 ms
11,076 KB
testcase_15 AC 53 ms
8,192 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 54 ms
8,168 KB
testcase_18 AC 104 ms
13,516 KB
testcase_19 AC 95 ms
12,384 KB
testcase_20 AC 97 ms
12,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

var
  g: seq[seq[int]]
  ans = 0

proc f(i, p: int): bool =
  var cnt = 0
  for j in g[i]:
    if j!=p:
      if not f(j, i):
        cnt+=1
  result = cnt>0
  if not result: ans+=1

proc main() =
  let n = stdin.readLine.parseInt
  g = newSeqWith(n, newSeq[int]())
  for _ in 1..<n:
    let ab = stdin.readLine.split.map(parseInt)
    g[ab[0]-1].add(ab[1]-1)
    g[ab[1]-1].add(ab[0]-1)
  let _ = f(0, -1)
  echo ans
main()
0