結果

問題 No.1637 Easy Tree Query
ユーザー H20
提出日時 2021-08-06 21:29:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 177,912 KB
最終ジャッジ日時 2024-09-17 03:40:36
合計ジャッジ時間 10,833 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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