結果

問題 No.1637 Easy Tree Query
ユーザー convexineqconvexineq
提出日時 2021-08-06 21:24:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 491 ms / 2,000 ms
コード長 543 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 81,672 KB
実行使用メモリ 95,908 KB
最終ジャッジ日時 2023-10-17 04:41:07
合計ジャッジ時間 13,609 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,428 KB
testcase_01 AC 37 ms
53,428 KB
testcase_02 AC 417 ms
95,660 KB
testcase_03 AC 37 ms
53,428 KB
testcase_04 AC 196 ms
86,040 KB
testcase_05 AC 370 ms
83,164 KB
testcase_06 AC 276 ms
81,156 KB
testcase_07 AC 194 ms
76,648 KB
testcase_08 AC 178 ms
84,092 KB
testcase_09 AC 334 ms
91,504 KB
testcase_10 AC 231 ms
79,832 KB
testcase_11 AC 415 ms
92,884 KB
testcase_12 AC 398 ms
86,932 KB
testcase_13 AC 154 ms
80,340 KB
testcase_14 AC 273 ms
91,520 KB
testcase_15 AC 410 ms
93,180 KB
testcase_16 AC 342 ms
95,632 KB
testcase_17 AC 188 ms
80,180 KB
testcase_18 AC 353 ms
83,136 KB
testcase_19 AC 363 ms
85,444 KB
testcase_20 AC 428 ms
87,708 KB
testcase_21 AC 275 ms
86,048 KB
testcase_22 AC 444 ms
95,908 KB
testcase_23 AC 184 ms
81,448 KB
testcase_24 AC 239 ms
86,316 KB
testcase_25 AC 375 ms
82,484 KB
testcase_26 AC 433 ms
90,128 KB
testcase_27 AC 491 ms
92,444 KB
testcase_28 AC 299 ms
81,748 KB
testcase_29 AC 353 ms
87,420 KB
testcase_30 AC 200 ms
87,416 KB
testcase_31 AC 290 ms
75,912 KB
testcase_32 AC 237 ms
82,612 KB
testcase_33 AC 359 ms
80,268 KB
testcase_34 AC 156 ms
95,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,Q = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
 
order = []
st = [0]
parent = [-1]*n
#depth = [0]*n
while st:
    v = st.pop()
    order.append(v)
    for c in g[v]:
        if c != parent[v]:
            st.append(c)
            parent[c] = v

size = [1]*n
for i in order[::-1]:
    if i==0: break
    size[parent[i]] += size[i]

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