結果

問題 No.806 木を道に
ユーザー nadeshinonadeshino
提出日時 2019-03-22 22:05:06
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,016 bytes
コンパイル時間 983 ms
コンパイル使用メモリ 67,996 KB
最終ジャッジ日時 2023-09-14 15:29:43
合計ジャッジ時間 1,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
stack trace: (most recent call last)
Main.nim(6, 9)           unpack
/home/judge/data/code/Main.nim(23, 14) template/generic instantiation of `input` from here
/home/judge/data/code/Main.nim(17, 43) template/generic instantiation of `unpack` from here
/home/judge/data/code/Main.nim(6, 9) Error: index 1 not in 0 .. 0

ソースコード

diff #

import algorithm, hashes, macros, math, sequtils, sets, strutils, tables, times, unicode

macro unpack*(rhs: seq, cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `rhs`;())
  if NimMinor <= 17:
    for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`])
  else:
    for i in 0..<cnt: result[1].add(quote do:`t`[`i`])

template input*(typ: typedesc, cnt: Natural = 0): untyped =
  let line = stdin.readLine.split(" ")
  when cnt == 0:
    when typ is int:    @[0]   & line.map(parseInt)
    elif typ is float:  @[0.0] & line.map(parseFloat)
    elif typ is string: @["#"] & line
  else:
    when typ is int:    line.map(parseInt).unpack(cnt)
    elif typ is float:  line.map(parseFloat).unpack(cnt)
    elif typ is string: "#" & line.unpack(cnt)

# -------------------------------------------------- #

var N = input(int, 1)
var deg = newseq[int](N + 1)

for i in 1..<N:
  var (a, b) = input(int, 2)
  deg[a] += 1
  deg[b] += 1

var res = 0
for i in 1..N:
  res += max(0, deg[i] - 2)

echo res
0