結果

問題 No.1637 Easy Tree Query
ユーザー ntudantuda
提出日時 2021-08-18 23:45:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 177,832 KB
最終ジャッジ日時 2024-04-20 03:32:24
合計ジャッジ時間 9,724 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,984 KB
testcase_01 AC 35 ms
53,148 KB
testcase_02 AC 292 ms
109,348 KB
testcase_03 AC 36 ms
54,004 KB
testcase_04 AC 173 ms
89,240 KB
testcase_05 AC 223 ms
95,560 KB
testcase_06 AC 184 ms
89,648 KB
testcase_07 AC 132 ms
80,936 KB
testcase_08 AC 153 ms
86,716 KB
testcase_09 AC 243 ms
98,880 KB
testcase_10 AC 155 ms
85,964 KB
testcase_11 AC 269 ms
103,796 KB
testcase_12 AC 255 ms
100,284 KB
testcase_13 AC 134 ms
83,188 KB
testcase_14 AC 215 ms
96,520 KB
testcase_15 AC 282 ms
103,520 KB
testcase_16 AC 260 ms
102,220 KB
testcase_17 AC 148 ms
84,228 KB
testcase_18 AC 215 ms
94,404 KB
testcase_19 AC 220 ms
95,004 KB
testcase_20 AC 255 ms
100,600 KB
testcase_21 AC 194 ms
92,704 KB
testcase_22 AC 294 ms
107,000 KB
testcase_23 AC 150 ms
84,972 KB
testcase_24 AC 186 ms
91,504 KB
testcase_25 AC 227 ms
94,400 KB
testcase_26 AC 266 ms
101,732 KB
testcase_27 AC 310 ms
107,832 KB
testcase_28 AC 200 ms
90,740 KB
testcase_29 AC 242 ms
97,572 KB
testcase_30 AC 175 ms
90,456 KB
testcase_31 AC 153 ms
86,036 KB
testcase_32 AC 166 ms
88,092 KB
testcase_33 AC 217 ms
91,652 KB
testcase_34 AC 271 ms
177,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(100000)

N,Q = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N-1)]
PX = [list(map(int,input().split())) for _ in range(Q)]
E = [[] for _ in range(N)]

for ab in AB:
    a,b = ab
    E[a-1].append(b-1)
    E[b-1].append(a-1)
dp = [0] * N

def dfs(x,p):
    cnt = 1
    for i in E[x]:
        if i != p:
            cnt += dfs(i,x)
    dp[x] = cnt
    return cnt

dfs(0,-1)
ans = 0
for px in PX:
    p,x = px
    ans += dp[p-1] * x
    print(ans)
0