結果

問題 No.763 Noelちゃんと木遊び
ユーザー simansiman
提出日時 2021-08-20 07:03:01
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 381 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-04-21 10:22:40
合計ジャッジ時間 6,441 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 162 ms
15,360 KB
testcase_02 AC 258 ms
19,328 KB
testcase_03 AC 196 ms
17,920 KB
testcase_04 AC 166 ms
15,616 KB
testcase_05 AC 193 ms
17,408 KB
testcase_06 AC 296 ms
22,528 KB
testcase_07 AC 281 ms
22,016 KB
testcase_08 AC 203 ms
18,048 KB
testcase_09 AC 165 ms
15,488 KB
testcase_10 AC 117 ms
13,568 KB
testcase_11 AC 311 ms
22,400 KB
testcase_12 AC 277 ms
21,504 KB
testcase_13 AC 272 ms
21,248 KB
testcase_14 AC 247 ms
18,816 KB
testcase_15 AC 198 ms
17,792 KB
testcase_16 AC 106 ms
13,056 KB
testcase_17 AC 201 ms
17,792 KB
testcase_18 AC 305 ms
22,272 KB
testcase_19 AC 282 ms
21,504 KB
testcase_20 AC 278 ms
21,504 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
E = Array.new(N + 1) { [] }

(N - 1).times do
  u, v = gets.split.map(&:to_i)
  E[u] << v
  E[v] << u
end

used = Array.new(N + 1, false)

def dfs(u, parent, used)
  has_child = false

  E[u].each do |v|
    next if v == parent

    dfs(v, u, used)
    has_child = true if used[v]
  end

  used[u] = true if not has_child
end

dfs(1, -1, used)

puts used.count(true)
0