結果

問題 No.1637 Easy Tree Query
ユーザー tonyu0tonyu0
提出日時 2022-09-21 17:39:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,039 ms / 2,000 ms
コード長 457 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 45,032 KB
最終ジャッジ日時 2023-08-23 20:06:36
合計ジャッジ時間 22,083 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,816 KB
testcase_01 AC 16 ms
7,876 KB
testcase_02 AC 962 ms
25,556 KB
testcase_03 AC 16 ms
7,824 KB
testcase_04 AC 297 ms
17,184 KB
testcase_05 AC 723 ms
14,612 KB
testcase_06 AC 486 ms
13,024 KB
testcase_07 AC 243 ms
8,620 KB
testcase_08 AC 238 ms
15,136 KB
testcase_09 AC 672 ms
21,248 KB
testcase_10 AC 342 ms
11,996 KB
testcase_11 AC 889 ms
22,740 KB
testcase_12 AC 829 ms
19,436 KB
testcase_13 AC 163 ms
12,208 KB
testcase_14 AC 497 ms
21,688 KB
testcase_15 AC 832 ms
23,332 KB
testcase_16 AC 716 ms
24,792 KB
testcase_17 AC 250 ms
12,212 KB
testcase_18 AC 676 ms
14,748 KB
testcase_19 AC 683 ms
16,016 KB
testcase_20 AC 865 ms
19,068 KB
testcase_21 AC 478 ms
17,404 KB
testcase_22 AC 987 ms
25,408 KB
testcase_23 AC 250 ms
13,152 KB
testcase_24 AC 400 ms
17,296 KB
testcase_25 AC 734 ms
14,228 KB
testcase_26 AC 891 ms
20,116 KB
testcase_27 AC 1,039 ms
24,552 KB
testcase_28 AC 531 ms
13,808 KB
testcase_29 AC 698 ms
18,568 KB
testcase_30 AC 309 ms
18,640 KB
testcase_31 AC 540 ms
7,696 KB
testcase_32 AC 364 ms
14,224 KB
testcase_33 AC 675 ms
12,148 KB
testcase_34 AC 420 ms
45,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(200000)
n,q=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(lambda x: int(x)-1,input().split())
    g[a].append(b)
    g[b].append(a)

ch=[0]*n
def rec(v, p= -1):
    ret = 1
    for nv in g[v]:
        if nv==p:continue
        ret += rec(nv, v)
    ch[v] = ret
    return ret
rec(0)
ans=0
for _ in range(q):
    p,x=map(int,input().split())
    p -= 1
    ans += ch[p] * x
    print(ans)
0