結果

問題 No.1637 Easy Tree Query
ユーザー kohei2019kohei2019
提出日時 2022-06-26 09:46:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 295 ms / 2,000 ms
コード長 514 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,664 KB
実行使用メモリ 179,360 KB
最終ジャッジ日時 2024-04-28 01:58:00
合計ジャッジ時間 10,488 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
51,968 KB
testcase_01 AC 35 ms
52,096 KB
testcase_02 AC 250 ms
97,152 KB
testcase_03 AC 34 ms
53,400 KB
testcase_04 AC 162 ms
83,900 KB
testcase_05 AC 220 ms
89,088 KB
testcase_06 AC 177 ms
85,752 KB
testcase_07 AC 137 ms
80,088 KB
testcase_08 AC 151 ms
82,432 KB
testcase_09 AC 230 ms
90,496 KB
testcase_10 AC 147 ms
83,168 KB
testcase_11 AC 267 ms
94,080 KB
testcase_12 AC 243 ms
92,512 KB
testcase_13 AC 132 ms
80,256 KB
testcase_14 AC 212 ms
87,680 KB
testcase_15 AC 261 ms
93,212 KB
testcase_16 AC 254 ms
91,776 KB
testcase_17 AC 139 ms
81,596 KB
testcase_18 AC 213 ms
88,708 KB
testcase_19 AC 212 ms
88,788 KB
testcase_20 AC 258 ms
92,800 KB
testcase_21 AC 186 ms
86,604 KB
testcase_22 AC 292 ms
95,932 KB
testcase_23 AC 147 ms
82,172 KB
testcase_24 AC 179 ms
85,120 KB
testcase_25 AC 222 ms
89,856 KB
testcase_26 AC 250 ms
93,112 KB
testcase_27 AC 295 ms
96,580 KB
testcase_28 AC 183 ms
86,260 KB
testcase_29 AC 230 ms
90,284 KB
testcase_30 AC 169 ms
84,928 KB
testcase_31 AC 157 ms
84,360 KB
testcase_32 AC 163 ms
84,096 KB
testcase_33 AC 201 ms
87,496 KB
testcase_34 AC 277 ms
179,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
N,Q = map(int,input().split())
lsg = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1 
    b -= 1
    lsg[a].append(b)
    lsg[b].append(a)
lsq = [tuple(map(int,input().split())) for i in range(Q)]

lsc = [1]*(N)
def dfs(k,p):
    for j in lsg[k]:
        if j == p:
            continue
        lsc[k] += dfs(j,k)
    return lsc[k]
dfs(0,-1)

ans = 0
for i in range(Q):
    p,x = lsq[i]
    p -= 1
    ans += lsc[p]*x
    print(ans)
0