結果

問題 No.1637 Easy Tree Query
ユーザー 👑 H20H20
提出日時 2021-08-06 21:29:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 491 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 1,060 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 175,828 KB
最終ジャッジ日時 2023-10-17 04:57:36
合計ジャッジ時間 13,503 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,424 KB
testcase_01 AC 37 ms
53,424 KB
testcase_02 AC 419 ms
89,096 KB
testcase_03 AC 36 ms
53,424 KB
testcase_04 AC 204 ms
83,164 KB
testcase_05 AC 381 ms
81,284 KB
testcase_06 AC 277 ms
80,516 KB
testcase_07 AC 189 ms
76,824 KB
testcase_08 AC 174 ms
81,580 KB
testcase_09 AC 339 ms
86,164 KB
testcase_10 AC 223 ms
79,164 KB
testcase_11 AC 422 ms
87,268 KB
testcase_12 AC 417 ms
85,128 KB
testcase_13 AC 157 ms
79,368 KB
testcase_14 AC 276 ms
86,796 KB
testcase_15 AC 407 ms
87,712 KB
testcase_16 AC 353 ms
89,400 KB
testcase_17 AC 191 ms
79,320 KB
testcase_18 AC 359 ms
81,112 KB
testcase_19 AC 364 ms
82,592 KB
testcase_20 AC 416 ms
84,932 KB
testcase_21 AC 271 ms
83,188 KB
testcase_22 AC 456 ms
89,444 KB
testcase_23 AC 186 ms
80,244 KB
testcase_24 AC 235 ms
83,252 KB
testcase_25 AC 384 ms
80,744 KB
testcase_26 AC 446 ms
85,420 KB
testcase_27 AC 491 ms
89,168 KB
testcase_28 AC 304 ms
80,664 KB
testcase_29 AC 357 ms
84,084 KB
testcase_30 AC 201 ms
83,996 KB
testcase_31 AC 287 ms
75,908 KB
testcase_32 AC 232 ms
81,060 KB
testcase_33 AC 357 ms
79,212 KB
testcase_34 AC 306 ms
175,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 8)

N,Q = map(int, input().split())
L = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int, input().split())
    L[a].append(b)
    L[b].append(a)
C = [0]*(N+1)

DE = [0]*(N+1)
def dfs(i,b):
    for l in L[i]:
        if l==b:
            continue
        dfs(l,i)
    DE[i]+=1
    DE[b]+=DE[i]

dfs(1,0)

ans = 0

for i in range(Q):
    p,x = map(int, input().split())
    ans += DE[p]*x
    print(ans)
0