結果

問題 No.1637 Easy Tree Query
ユーザー tonyu0tonyu0
提出日時 2022-09-21 17:37:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 416 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 10,788 KB
実行使用メモリ 25,704 KB
最終ジャッジ日時 2023-08-23 20:05:49
合計ジャッジ時間 23,173 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,772 KB
testcase_01 AC 16 ms
7,784 KB
testcase_02 AC 955 ms
25,364 KB
testcase_03 AC 16 ms
7,828 KB
testcase_04 AC 302 ms
17,272 KB
testcase_05 AC 725 ms
14,648 KB
testcase_06 AC 485 ms
12,992 KB
testcase_07 AC 241 ms
8,488 KB
testcase_08 AC 241 ms
15,136 KB
testcase_09 AC 667 ms
21,228 KB
testcase_10 AC 336 ms
11,928 KB
testcase_11 AC 885 ms
22,584 KB
testcase_12 AC 867 ms
19,448 KB
testcase_13 AC 163 ms
12,168 KB
testcase_14 AC 505 ms
21,644 KB
testcase_15 AC 827 ms
23,388 KB
testcase_16 AC 694 ms
24,876 KB
testcase_17 AC 240 ms
12,208 KB
testcase_18 AC 680 ms
14,588 KB
testcase_19 AC 674 ms
15,944 KB
testcase_20 AC 861 ms
19,144 KB
testcase_21 AC 472 ms
17,304 KB
testcase_22 AC 965 ms
25,284 KB
testcase_23 AC 249 ms
13,248 KB
testcase_24 AC 403 ms
17,400 KB
testcase_25 AC 716 ms
14,224 KB
testcase_26 AC 880 ms
19,916 KB
testcase_27 AC 1,026 ms
24,348 KB
testcase_28 AC 538 ms
13,788 KB
testcase_29 AC 705 ms
18,580 KB
testcase_30 AC 309 ms
18,568 KB
testcase_31 AC 540 ms
7,876 KB
testcase_32 AC 369 ms
14,168 KB
testcase_33 AC 663 ms
12,096 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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