結果

問題 No.1637 Easy Tree Query
ユーザー wgrapewgrape
提出日時 2023-11-01 15:07:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 538 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 176,948 KB
最終ジャッジ日時 2023-11-01 15:07:14
合計ジャッジ時間 13,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,588 KB
testcase_01 AC 36 ms
53,588 KB
testcase_02 AC 395 ms
88,708 KB
testcase_03 AC 53 ms
53,588 KB
testcase_04 AC 194 ms
82,680 KB
testcase_05 AC 369 ms
81,112 KB
testcase_06 AC 279 ms
80,312 KB
testcase_07 AC 180 ms
76,928 KB
testcase_08 AC 175 ms
81,412 KB
testcase_09 AC 330 ms
85,744 KB
testcase_10 AC 214 ms
79,152 KB
testcase_11 AC 426 ms
86,780 KB
testcase_12 AC 393 ms
84,420 KB
testcase_13 AC 151 ms
79,348 KB
testcase_14 AC 268 ms
86,256 KB
testcase_15 AC 402 ms
87,200 KB
testcase_16 AC 349 ms
88,708 KB
testcase_17 AC 177 ms
79,300 KB
testcase_18 AC 346 ms
80,988 KB
testcase_19 AC 339 ms
82,532 KB
testcase_20 AC 411 ms
84,508 KB
testcase_21 AC 268 ms
82,936 KB
testcase_22 AC 452 ms
88,776 KB
testcase_23 AC 179 ms
80,204 KB
testcase_24 AC 234 ms
83,000 KB
testcase_25 AC 368 ms
80,644 KB
testcase_26 AC 420 ms
84,856 KB
testcase_27 AC 476 ms
88,328 KB
testcase_28 AC 291 ms
80,580 KB
testcase_29 AC 345 ms
84,420 KB
testcase_30 AC 197 ms
83,708 KB
testcase_31 AC 269 ms
76,064 KB
testcase_32 AC 223 ms
80,868 KB
testcase_33 AC 337 ms
79,200 KB
testcase_34 AC 298 ms
176,948 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)
    
cnt = [0] * N # 自分を含む子の数
def dfs(v, p):
    c = 1
    for child in G[v]:
        if child == p:
            continue
        c += dfs(child, v)
    cnt[v] = c
    return c
    
dfs(0, -1)
        
ans = 0
for _ in range(Q):
    p,x = map(int,input().split())
    ans += cnt[p - 1] * x
    print(ans)
    
0