結果
問題 |
No.1637 Easy Tree Query
|
ユーザー |
|
提出日時 | 2021-11-01 16:25:17 |
言語 | Ruby (3.4.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 484 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 30,080 KB |
最終ジャッジ日時 | 2024-10-10 06:56:29 |
合計ジャッジ時間 | 17,347 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 32 RE * 1 |
コンパイルメッセージ
Syntax OK
ソースコード
N, Q = gets.split(" ").map{|s| s.to_i} $v = Array.new(N) {Array.new} $w = Array.new(N, 1) (N-1).times { a, b = gets.split(" ").map{|s| s.to_i} $v[b-1] << a-1 $v[a-1] << b-1 } q = [] Q.times { q << gets.split(" ").map{|s| s.to_i} } def search(from, to) return 1 if from >= 0 and $v[to].length == 1 $v[to].each {|i| if i != from then n = search(to, i) $w[to] += n end } return $w[to] end search(-1, 0) total = 0 q.each{|p, x| total += $w[p-1] * x puts total }