結果

問題 No.763 Noelちゃんと木遊び
ユーザー むらためむらため
提出日時 2019-01-30 00:59:11
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,000 bytes
コンパイル時間 2,800 ms
コンパイル使用メモリ 67,032 KB
実行使用メモリ 21,932 KB
最終ジャッジ日時 2023-09-14 03:12:55
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
21,932 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

let n = scan()
var E = newSeqWith(n,newSeq[int]())
(n-1).times: E[scan()-1] &= scan()-1
var preHasCutDP = newSeqWith(n,-1)
var preHasNotCutDP = newSeqWith(n,-1)
# var time = 0
proc solve(preHasCut:bool,x:int):int =
  if E[x].len == 0 : return if preHasCut: 1 else: 0
  if preHasCut and preHasCutDP[x] != -1 : return preHasCutDP[x]
  if not preHasCut and preHasNotCutDP[x] != -1 : return preHasNotCutDP[x]
  # time += 1
  var whenCut = 0
  for e in E[x]: whenCut += solve(true,e)
  var whenNotCut = 0
  for e in E[x]: whenNotCut += solve(false,e)
  if preHasCut : whenNotCut += 1
  result = max(whenCut,whenNotCut)
  if preHasCut:preHasCutDP[x] = result
  else: preHasNotCutDP[x] = result
echo solve(true,0)
# echo time
0