結果

問題 No.1637 Easy Tree Query
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-08-06 21:27:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 488 bytes
コンパイル時間 884 ms
コンパイル使用メモリ 81,720 KB
実行使用メモリ 176,624 KB
最終ジャッジ日時 2023-10-17 04:52:25
合計ジャッジ時間 12,602 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,484 KB
testcase_01 AC 37 ms
53,484 KB
testcase_02 AC 415 ms
88,584 KB
testcase_03 AC 36 ms
53,484 KB
testcase_04 AC 187 ms
82,576 KB
testcase_05 AC 367 ms
81,012 KB
testcase_06 AC 271 ms
80,216 KB
testcase_07 AC 187 ms
76,848 KB
testcase_08 AC 167 ms
81,312 KB
testcase_09 AC 317 ms
85,628 KB
testcase_10 AC 218 ms
79,048 KB
testcase_11 AC 398 ms
86,660 KB
testcase_12 AC 392 ms
84,308 KB
testcase_13 AC 151 ms
79,236 KB
testcase_14 AC 248 ms
86,148 KB
testcase_15 AC 380 ms
87,088 KB
testcase_16 AC 328 ms
88,604 KB
testcase_17 AC 179 ms
79,180 KB
testcase_18 AC 344 ms
80,884 KB
testcase_19 AC 346 ms
82,344 KB
testcase_20 AC 402 ms
84,404 KB
testcase_21 AC 256 ms
82,832 KB
testcase_22 AC 433 ms
88,664 KB
testcase_23 AC 180 ms
80,092 KB
testcase_24 AC 225 ms
82,884 KB
testcase_25 AC 364 ms
80,532 KB
testcase_26 AC 409 ms
84,740 KB
testcase_27 AC 468 ms
88,236 KB
testcase_28 AC 290 ms
80,472 KB
testcase_29 AC 335 ms
84,300 KB
testcase_30 AC 180 ms
83,596 KB
testcase_31 AC 285 ms
75,956 KB
testcase_32 AC 216 ms
80,768 KB
testcase_33 AC 343 ms
79,088 KB
testcase_34 AC 279 ms
176,624 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