結果

問題 No.1637 Easy Tree Query
ユーザー lloyzlloyz
提出日時 2021-12-24 23:34:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 565 bytes
コンパイル時間 231 ms
コンパイル使用メモリ 81,912 KB
実行使用メモリ 179,012 KB
最終ジャッジ日時 2023-10-20 03:06:24
合計ジャッジ時間 13,348 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,532 KB
testcase_01 AC 43 ms
55,532 KB
testcase_02 AC 423 ms
94,536 KB
testcase_03 AC 40 ms
55,532 KB
testcase_04 AC 212 ms
87,292 KB
testcase_05 AC 377 ms
84,244 KB
testcase_06 AC 282 ms
82,924 KB
testcase_07 AC 191 ms
77,124 KB
testcase_08 AC 185 ms
84,900 KB
testcase_09 AC 341 ms
90,964 KB
testcase_10 AC 227 ms
81,504 KB
testcase_11 AC 429 ms
93,004 KB
testcase_12 AC 423 ms
90,104 KB
testcase_13 AC 163 ms
82,032 KB
testcase_14 AC 281 ms
90,308 KB
testcase_15 AC 413 ms
93,336 KB
testcase_16 AC 362 ms
94,984 KB
testcase_17 AC 190 ms
81,856 KB
testcase_18 AC 358 ms
84,876 KB
testcase_19 AC 354 ms
85,152 KB
testcase_20 AC 421 ms
88,860 KB
testcase_21 AC 273 ms
86,820 KB
testcase_22 AC 463 ms
94,800 KB
testcase_23 AC 190 ms
83,352 KB
testcase_24 AC 247 ms
87,552 KB
testcase_25 AC 375 ms
84,592 KB
testcase_26 AC 431 ms
90,320 KB
testcase_27 AC 486 ms
95,068 KB
testcase_28 AC 303 ms
83,932 KB
testcase_29 AC 361 ms
88,544 KB
testcase_30 AC 209 ms
88,420 KB
testcase_31 AC 284 ms
77,048 KB
testcase_32 AC 230 ms
84,592 KB
testcase_33 AC 347 ms
81,816 KB
testcase_34 AC 310 ms
179,012 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