結果

問題 No.1637 Easy Tree Query
ユーザー 小野寺健小野寺健
提出日時 2021-11-01 16:25:17
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 484 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 29,952 KB
最終ジャッジ日時 2024-04-18 13:44:25
合計ジャッジ時間 15,696 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
12,288 KB
testcase_01 AC 83 ms
12,288 KB
testcase_02 AC 561 ms
25,344 KB
testcase_03 AC 81 ms
12,160 KB
testcase_04 AC 223 ms
17,792 KB
testcase_05 AC 423 ms
22,016 KB
testcase_06 AC 305 ms
18,048 KB
testcase_07 AC 193 ms
15,232 KB
testcase_08 AC 199 ms
16,640 KB
testcase_09 AC 395 ms
23,936 KB
testcase_10 AC 247 ms
17,152 KB
testcase_11 AC 490 ms
24,576 KB
testcase_12 AC 476 ms
23,680 KB
testcase_13 AC 159 ms
14,592 KB
testcase_14 AC 292 ms
21,248 KB
testcase_15 AC 463 ms
25,472 KB
testcase_16 AC 420 ms
23,168 KB
testcase_17 AC 196 ms
15,872 KB
testcase_18 AC 500 ms
21,888 KB
testcase_19 AC 386 ms
21,248 KB
testcase_20 AC 485 ms
23,808 KB
testcase_21 AC 297 ms
20,096 KB
testcase_22 AC 533 ms
26,752 KB
testcase_23 AC 196 ms
16,384 KB
testcase_24 AC 265 ms
19,584 KB
testcase_25 AC 425 ms
22,016 KB
testcase_26 AC 504 ms
24,064 KB
testcase_27 AC 592 ms
29,952 KB
testcase_28 AC 331 ms
20,608 KB
testcase_29 AC 399 ms
23,296 KB
testcase_30 AC 223 ms
18,432 KB
testcase_31 AC 331 ms
19,200 KB
testcase_32 AC 253 ms
18,560 KB
testcase_33 AC 402 ms
22,144 KB
testcase_34 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
}
0