結果

問題 No.1637 Easy Tree Query
ユーザー maguroflymagurofly
提出日時 2021-08-06 21:27:09
言語 Ruby
(3.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 471 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 11,800 KB
実行使用メモリ 31,200 KB
最終ジャッジ日時 2023-10-17 04:53:01
合計ジャッジ時間 14,613 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
16,016 KB
testcase_01 AC 87 ms
16,016 KB
testcase_02 AC 502 ms
25,568 KB
testcase_03 AC 86 ms
16,016 KB
testcase_04 AC 224 ms
21,344 KB
testcase_05 AC 379 ms
19,932 KB
testcase_06 AC 281 ms
18,760 KB
testcase_07 AC 175 ms
16,248 KB
testcase_08 AC 194 ms
20,416 KB
testcase_09 AC 377 ms
24,564 KB
testcase_10 AC 222 ms
18,240 KB
testcase_11 AC 459 ms
25,464 KB
testcase_12 AC 426 ms
21,972 KB
testcase_13 AC 155 ms
18,392 KB
testcase_14 AC 314 ms
24,756 KB
testcase_15 AC 459 ms
26,004 KB
testcase_16 AC 404 ms
26,640 KB
testcase_17 AC 192 ms
18,392 KB
testcase_18 AC 361 ms
19,932 KB
testcase_19 AC 388 ms
20,704 KB
testcase_20 AC 448 ms
21,956 KB
testcase_21 AC 295 ms
21,364 KB
testcase_22 AC 502 ms
26,864 KB
testcase_23 AC 189 ms
18,768 KB
testcase_24 AC 262 ms
21,380 KB
testcase_25 AC 381 ms
18,860 KB
testcase_26 AC 465 ms
22,528 KB
testcase_27 AC 521 ms
26,592 KB
testcase_28 AC 298 ms
18,932 KB
testcase_29 AC 375 ms
21,668 KB
testcase_30 AC 229 ms
21,664 KB
testcase_31 AC 289 ms
16,132 KB
testcase_32 AC 243 ms
19,088 KB
testcase_33 AC 349 ms
18,316 KB
testcase_34 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, Q = gets.split.map(&:to_i)
graph = Array.new(N) { [] }
(N - 1).times do
    u, v = gets.split.map(&:to_i)
    graph[u - 1] << v - 1
    graph[v - 1] << u - 1
end

weight = Array.new(N, 1)
visited = Array.new(N, false)
dfs = ->(u) {
    visited[u] = true
    graph[u].each do |v|
        next if visited[v]
        dfs[v]
        weight[u] += weight[v]
    end
}
dfs[0]

sum = 0
Q.times do
    v, c = gets.split.map(&:to_i)
    sum += weight[v - 1] * c
    puts sum
end
0