結果

問題 No.1637 Easy Tree Query
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-08-06 21:26:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,008 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 11,884 KB
実行使用メモリ 47,128 KB
最終ジャッジ日時 2023-10-17 04:51:14
合計ジャッジ時間 21,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,172 KB
testcase_01 AC 29 ms
10,172 KB
testcase_02 AC 976 ms
27,420 KB
testcase_03 AC 28 ms
10,172 KB
testcase_04 AC 287 ms
19,196 KB
testcase_05 AC 732 ms
16,628 KB
testcase_06 AC 496 ms
14,896 KB
testcase_07 AC 260 ms
10,548 KB
testcase_08 AC 234 ms
17,136 KB
testcase_09 AC 636 ms
23,296 KB
testcase_10 AC 353 ms
13,980 KB
testcase_11 AC 857 ms
24,652 KB
testcase_12 AC 805 ms
21,468 KB
testcase_13 AC 166 ms
14,068 KB
testcase_14 AC 460 ms
23,680 KB
testcase_15 AC 799 ms
25,428 KB
testcase_16 AC 658 ms
26,884 KB
testcase_17 AC 253 ms
14,092 KB
testcase_18 AC 702 ms
16,624 KB
testcase_19 AC 693 ms
17,948 KB
testcase_20 AC 850 ms
21,072 KB
testcase_21 AC 462 ms
19,324 KB
testcase_22 AC 922 ms
27,284 KB
testcase_23 AC 250 ms
15,160 KB
testcase_24 AC 390 ms
19,348 KB
testcase_25 AC 736 ms
16,156 KB
testcase_26 AC 873 ms
21,980 KB
testcase_27 AC 1,008 ms
26,456 KB
testcase_28 AC 546 ms
15,728 KB
testcase_29 AC 683 ms
20,588 KB
testcase_30 AC 289 ms
20,500 KB
testcase_31 AC 572 ms
10,220 KB
testcase_32 AC 373 ms
16,244 KB
testcase_33 AC 687 ms
14,128 KB
testcase_34 AC 409 ms
47,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
n, q = map(int, input().split())
G = [[] for i in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
dp = [0] * n
def dfs(prev, cur):
    res = 1
    for nex in G[cur]:
        if nex != prev:
            res += dfs(cur, nex)
    dp[cur] = res
    return res
ans = 0
dfs(-1, 0)
for _ in range(q):
    p, x = map(int, input().split())
    ans += x * dp[p - 1]
    print(ans)
0