結果

問題 No.1637 Easy Tree Query
ユーザー lloyzlloyz
提出日時 2021-12-24 23:33:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,086 ms / 2,000 ms
コード長 594 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 11,976 KB
実行使用メモリ 50,484 KB
最終ジャッジ日時 2023-10-20 03:04:57
合計ジャッジ時間 24,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,108 KB
testcase_01 AC 29 ms
10,108 KB
testcase_02 AC 1,006 ms
31,636 KB
testcase_03 AC 29 ms
10,108 KB
testcase_04 AC 317 ms
21,020 KB
testcase_05 AC 735 ms
17,324 KB
testcase_06 AC 493 ms
15,740 KB
testcase_07 AC 258 ms
10,572 KB
testcase_08 AC 259 ms
17,856 KB
testcase_09 AC 692 ms
24,988 KB
testcase_10 AC 360 ms
14,092 KB
testcase_11 AC 887 ms
26,304 KB
testcase_12 AC 844 ms
23,132 KB
testcase_13 AC 175 ms
15,416 KB
testcase_14 AC 506 ms
25,248 KB
testcase_15 AC 876 ms
27,100 KB
testcase_16 AC 749 ms
31,712 KB
testcase_17 AC 268 ms
15,412 KB
testcase_18 AC 706 ms
17,324 KB
testcase_19 AC 689 ms
20,764 KB
testcase_20 AC 896 ms
22,872 KB
testcase_21 AC 511 ms
21,288 KB
testcase_22 AC 1,021 ms
31,712 KB
testcase_23 AC 269 ms
16,004 KB
testcase_24 AC 434 ms
21,284 KB
testcase_25 AC 754 ms
16,800 KB
testcase_26 AC 938 ms
23,928 KB
testcase_27 AC 1,086 ms
31,712 KB
testcase_28 AC 561 ms
16,532 KB
testcase_29 AC 720 ms
22,344 KB
testcase_30 AC 333 ms
22,340 KB
testcase_31 AC 564 ms
10,168 KB
testcase_32 AC 393 ms
17,064 KB
testcase_33 AC 693 ms
15,412 KB
testcase_34 AC 462 ms
50,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
edge = defaultdict(list)
for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

V = [0 for _ in range(n)]
def dfs(curr, prev):
    V[curr] += 1
    for np in edge[curr]:
        if np == prev:
            continue
        dfs(np, curr)
        V[curr] += V[np]
dfs(0, -1)

ans = 0
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans += x * V[p]
    print(ans)
0