結果

問題 No.1637 Easy Tree Query
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-08 15:15:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 81,716 KB
実行使用メモリ 96,984 KB
最終ジャッジ日時 2023-10-19 15:27:33
合計ジャッジ時間 8,514 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,448 KB
testcase_01 AC 35 ms
53,448 KB
testcase_02 AC 141 ms
96,768 KB
testcase_03 AC 35 ms
53,464 KB
testcase_04 AC 101 ms
85,352 KB
testcase_05 AC 118 ms
84,216 KB
testcase_06 AC 106 ms
81,824 KB
testcase_07 AC 78 ms
76,756 KB
testcase_08 AC 98 ms
83,568 KB
testcase_09 AC 138 ms
91,820 KB
testcase_10 AC 92 ms
80,284 KB
testcase_11 AC 166 ms
94,288 KB
testcase_12 AC 146 ms
89,516 KB
testcase_13 AC 93 ms
80,100 KB
testcase_14 AC 149 ms
91,628 KB
testcase_15 AC 162 ms
94,756 KB
testcase_16 AC 164 ms
96,148 KB
testcase_17 AC 89 ms
80,096 KB
testcase_18 AC 118 ms
84,036 KB
testcase_19 AC 123 ms
85,288 KB
testcase_20 AC 147 ms
89,364 KB
testcase_21 AC 118 ms
86,708 KB
testcase_22 AC 171 ms
96,984 KB
testcase_23 AC 89 ms
81,216 KB
testcase_24 AC 124 ms
86,440 KB
testcase_25 AC 130 ms
83,480 KB
testcase_26 AC 149 ms
90,780 KB
testcase_27 AC 180 ms
96,736 KB
testcase_28 AC 107 ms
83,184 KB
testcase_29 AC 130 ms
88,500 KB
testcase_30 AC 119 ms
86,240 KB
testcase_31 AC 84 ms
77,696 KB
testcase_32 AC 102 ms
82,612 KB
testcase_33 AC 109 ms
81,872 KB
testcase_34 AC 93 ms
91,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, q = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)

s = []
order = []
par = [-1]*n
s.append(0)
while s:
    v = s.pop()
    order.append(v)
    for u in g[v]:
        if par[v] == u:
            continue
        par[u] = v
        s.append(u)
order.reverse()
C = [1]*n
for v in order:
    if par[v] != -1:
        C[par[v]] += C[v]

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