結果

問題 No.806 木を道に
ユーザー むらためむらため
提出日時 2019-05-17 21:58:00
言語 Nim
(2.0.2)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 996 bytes
コンパイル時間 2,476 ms
コンパイル使用メモリ 69,856 KB
実行使用メモリ 35,196 KB
最終ジャッジ日時 2023-09-14 18:30:25
合計ジャッジ時間 8,229 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 45 ms
8,816 KB
testcase_11 AC 16 ms
8,136 KB
testcase_12 AC 101 ms
25,468 KB
testcase_13 AC 59 ms
19,156 KB
testcase_14 AC 98 ms
24,208 KB
testcase_15 AC 101 ms
25,756 KB
testcase_16 AC 23 ms
11,052 KB
testcase_17 AC 72 ms
22,492 KB
testcase_18 AC 6 ms
5,108 KB
testcase_19 AC 44 ms
9,104 KB
testcase_20 AC 73 ms
22,416 KB
testcase_21 AC 42 ms
14,016 KB
testcase_22 AC 120 ms
29,236 KB
testcase_23 AC 116 ms
29,288 KB
testcase_24 AC 569 ms
26,792 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils
template times*(n:int,body) = (for _ in 0..<n: body)
template `max=`*(x,y) = x = max(x,y)
template `min=`*(x,y) = x = min(x,y)
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" ,discardable.}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord

# (親も子も同一視して)双方向になっている木を,0 番を根として子のノードだけ持つように変更する
proc asTree(E:seq[seq[int]]):seq[seq[int]] =
  var answer = newSeqWith(E.len,newSeq[int]())
  proc impl(pre,now:int) =
    for dst in E[now]:
      if dst == pre : continue
      answer[now].add(dst)
      impl(now,dst)
  impl(-1,0)
  return answer

let n = scan()
# 木やんけ
var E = newSeqWith(n,newSeq[int]())
(n-1).times:
  let a = scan() - 1
  let b = scan() - 1
  E[a] &= b
  E[b] &= a
E = E.asTree()
var ans = 0.max(E[0].len - 2)
for i in 1..<n:
  ans += 0.max(E[i].len - 1)
echo ans
0