結果

問題 No.1637 Easy Tree Query
ユーザー momoyuumomoyuu
提出日時 2022-08-03 00:56:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 502 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 191,512 KB
最終ジャッジ日時 2023-10-01 01:36:27
合計ジャッジ時間 17,223 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,264 KB
testcase_01 AC 72 ms
71,428 KB
testcase_02 AC 465 ms
100,612 KB
testcase_03 AC 70 ms
71,156 KB
testcase_04 AC 239 ms
90,472 KB
testcase_05 AC 393 ms
86,552 KB
testcase_06 AC 311 ms
85,012 KB
testcase_07 AC 220 ms
79,188 KB
testcase_08 AC 211 ms
87,432 KB
testcase_09 AC 358 ms
94,952 KB
testcase_10 AC 250 ms
82,952 KB
testcase_11 AC 446 ms
98,024 KB
testcase_12 AC 428 ms
92,680 KB
testcase_13 AC 191 ms
83,244 KB
testcase_14 AC 299 ms
95,516 KB
testcase_15 AC 427 ms
98,248 KB
testcase_16 AC 382 ms
100,332 KB
testcase_17 AC 222 ms
83,172 KB
testcase_18 AC 377 ms
86,328 KB
testcase_19 AC 374 ms
88,232 KB
testcase_20 AC 451 ms
92,840 KB
testcase_21 AC 296 ms
90,568 KB
testcase_22 AC 473 ms
100,824 KB
testcase_23 AC 217 ms
85,072 KB
testcase_24 AC 267 ms
90,456 KB
testcase_25 AC 397 ms
85,972 KB
testcase_26 AC 457 ms
93,464 KB
testcase_27 AC 502 ms
99,088 KB
testcase_28 AC 330 ms
85,220 KB
testcase_29 AC 392 ms
91,328 KB
testcase_30 AC 238 ms
91,148 KB
testcase_31 AC 300 ms
78,512 KB
testcase_32 AC 268 ms
86,080 KB
testcase_33 AC 373 ms
83,200 KB
testcase_34 AC 377 ms
191,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q = map(int,input().split())
def f(n):
    return int(n) - 1
ab = [list(map(f,input().split( ))) for _ in range(N-1)]
import sys
sys.setrecursionlimit(10**8)
e = [[] for _ in range(N)]
for i in range(N-1):
    a,b = ab[i]
    e[a].append(b)
    e[b].append(a)
d = [0 for _ in range(N)]
def dfs(n):
    d[n] += 1
    for i in e[n]:
        if d[i] != 0:
            continue
        dfs(i)
        d[n] += d[i]
dfs(0)
sum = 0

for i in range(Q):
    p,x = map(int,input().split())
    sum += d[p-1]*x
    print(sum)
0