結果

問題 No.1637 Easy Tree Query
ユーザー wgrapewgrape
提出日時 2023-11-01 15:05:36
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 496 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 91,920 KB
最終ジャッジ日時 2023-11-01 15:05:52
合計ジャッジ時間 14,376 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,624 KB
testcase_01 AC 38 ms
53,624 KB
testcase_02 AC 392 ms
88,740 KB
testcase_03 AC 35 ms
53,624 KB
testcase_04 AC 193 ms
82,724 KB
testcase_05 AC 355 ms
81,200 KB
testcase_06 AC 290 ms
80,344 KB
testcase_07 AC 179 ms
76,960 KB
testcase_08 AC 170 ms
81,452 KB
testcase_09 AC 324 ms
85,768 KB
testcase_10 AC 215 ms
79,184 KB
testcase_11 AC 425 ms
86,808 KB
testcase_12 AC 391 ms
84,484 KB
testcase_13 AC 147 ms
79,384 KB
testcase_14 AC 289 ms
86,196 KB
testcase_15 AC 392 ms
87,232 KB
testcase_16 AC 342 ms
88,680 KB
testcase_17 AC 178 ms
79,328 KB
testcase_18 AC 369 ms
81,020 KB
testcase_19 AC 339 ms
82,464 KB
testcase_20 AC 402 ms
84,448 KB
testcase_21 AC 261 ms
82,972 KB
testcase_22 AC 468 ms
88,820 KB
testcase_23 AC 177 ms
80,236 KB
testcase_24 AC 232 ms
83,040 KB
testcase_25 AC 358 ms
80,672 KB
testcase_26 AC 419 ms
84,892 KB
testcase_27 AC 468 ms
88,364 KB
testcase_28 AC 309 ms
80,540 KB
testcase_29 AC 342 ms
84,456 KB
testcase_30 AC 199 ms
83,736 KB
testcase_31 AC 266 ms
76,100 KB
testcase_32 AC 239 ms
80,912 KB
testcase_33 AC 331 ms
79,240 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q = map(int,input().split())
G = [[] for i in range(N)]

for _ in range(N - 1):
    a,b = map(int,input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
    
cnt = [0] * N # 自分を含む子の数
def dfs(v, p):
    c = 1
    for child in G[v]:
        if child == p:
            continue
        c += dfs(child, v)
    cnt[v] = c
    return c
    
dfs(0, -1)
        
ans = 0
for _ in range(Q):
    p,x = map(int,input().split())
    ans += cnt[p - 1] * x
    print(ans)
    
0