結果

問題 No.1637 Easy Tree Query
ユーザー playerplayer
提出日時 2023-12-20 00:48:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 592 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 178,800 KB
最終ジャッジ日時 2023-12-20 00:48:39
合計ジャッジ時間 15,670 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 547 ms
88,208 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 204 ms
82,712 KB
testcase_05 AC 436 ms
80,932 KB
testcase_06 AC 339 ms
79,704 KB
testcase_07 AC 199 ms
76,548 KB
testcase_08 AC 180 ms
81,216 KB
testcase_09 AC 380 ms
85,580 KB
testcase_10 AC 266 ms
78,896 KB
testcase_11 AC 489 ms
86,672 KB
testcase_12 AC 465 ms
84,216 KB
testcase_13 AC 158 ms
79,156 KB
testcase_14 AC 296 ms
85,852 KB
testcase_15 AC 462 ms
87,080 KB
testcase_16 AC 404 ms
88,312 KB
testcase_17 AC 192 ms
79,156 KB
testcase_18 AC 417 ms
80,804 KB
testcase_19 AC 410 ms
81,760 KB
testcase_20 AC 559 ms
84,072 KB
testcase_21 AC 329 ms
82,716 KB
testcase_22 AC 565 ms
88,576 KB
testcase_23 AC 186 ms
79,716 KB
testcase_24 AC 264 ms
82,980 KB
testcase_25 AC 465 ms
80,524 KB
testcase_26 AC 525 ms
84,760 KB
testcase_27 AC 592 ms
88,032 KB
testcase_28 AC 339 ms
80,120 KB
testcase_29 AC 412 ms
83,668 KB
testcase_30 AC 199 ms
83,792 KB
testcase_31 AC 366 ms
75,872 KB
testcase_32 AC 248 ms
80,532 KB
testcase_33 AC 424 ms
79,280 KB
testcase_34 AC 361 ms
178,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import pypyjit
import sys
sys.setrecursionlimit(10**6)
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