結果

問題 No.1637 Easy Tree Query
ユーザー playerplayer
提出日時 2023-12-20 00:42:27
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 504 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 91,928 KB
最終ジャッジ日時 2023-12-20 00:42:45
合計ジャッジ時間 16,754 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 497 ms
88,216 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 191 ms
82,720 KB
testcase_05 AC 475 ms
80,940 KB
testcase_06 AC 311 ms
79,712 KB
testcase_07 AC 201 ms
76,556 KB
testcase_08 AC 169 ms
81,224 KB
testcase_09 AC 389 ms
85,588 KB
testcase_10 AC 239 ms
78,904 KB
testcase_11 AC 479 ms
86,680 KB
testcase_12 AC 480 ms
84,224 KB
testcase_13 AC 145 ms
79,164 KB
testcase_14 AC 272 ms
85,860 KB
testcase_15 AC 438 ms
87,088 KB
testcase_16 AC 403 ms
88,320 KB
testcase_17 AC 191 ms
79,164 KB
testcase_18 AC 404 ms
80,812 KB
testcase_19 AC 425 ms
81,768 KB
testcase_20 AC 474 ms
84,080 KB
testcase_21 AC 280 ms
82,724 KB
testcase_22 AC 537 ms
88,584 KB
testcase_23 AC 185 ms
79,724 KB
testcase_24 AC 248 ms
82,988 KB
testcase_25 AC 452 ms
80,404 KB
testcase_26 AC 493 ms
84,768 KB
testcase_27 AC 568 ms
88,040 KB
testcase_28 AC 329 ms
80,128 KB
testcase_29 AC 389 ms
83,548 KB
testcase_30 AC 189 ms
83,800 KB
testcase_31 AC 371 ms
75,876 KB
testcase_32 AC 239 ms
80,540 KB
testcase_33 AC 408 ms
79,288 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

n,q = map(int,input().split())

edge = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    
cnt = [0]*n

def dfs(x,p):
    ret = 1
    for c in edge[x]:
        if c == p:
            continue
        ret += dfs(c,x)
    cnt[x] += ret
    return ret

dfs(0,-1)

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