結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
17,392 KB
testcase_01 AC 33 ms
6,376 KB
testcase_02 AC 84 ms
11,468 KB
testcase_03 AC 54 ms
8,284 KB
testcase_04 AC 37 ms
6,812 KB
testcase_05 AC 50 ms
8,252 KB
testcase_06 AC 101 ms
13,340 KB
testcase_07 AC 98 ms
12,992 KB
testcase_08 AC 55 ms
8,588 KB
testcase_09 AC 36 ms
6,772 KB
testcase_10 AC 15 ms
4,540 KB
testcase_11 AC 106 ms
13,460 KB
testcase_12 AC 93 ms
12,356 KB
testcase_13 AC 93 ms
12,060 KB
testcase_14 AC 80 ms
11,208 KB
testcase_15 AC 53 ms
8,204 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 52 ms
8,260 KB
testcase_18 AC 104 ms
13,404 KB
testcase_19 AC 96 ms
12,284 KB
testcase_20 AC 99 ms
12,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils

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

proc f(i, p: int): bool = # 頂点iを残すか
  result = true
  for j in g[i]:
    if j!=p:
      if f(j, i):
        result = false # 子が1つでも残っていれば頂点iを削除
  if 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