結果

問題 No.1637 Easy Tree Query
ユーザー yudai1102jpyudai1102jp
提出日時 2021-08-06 23:57:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,026 ms / 2,000 ms
コード長 750 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 11,848 KB
実行使用メモリ 45,540 KB
最終ジャッジ日時 2023-10-17 05:43:03
合計ジャッジ時間 21,515 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,212 KB
testcase_01 AC 30 ms
10,212 KB
testcase_02 AC 983 ms
27,448 KB
testcase_03 AC 30 ms
10,212 KB
testcase_04 AC 296 ms
19,244 KB
testcase_05 AC 745 ms
16,656 KB
testcase_06 AC 500 ms
14,928 KB
testcase_07 AC 260 ms
10,580 KB
testcase_08 AC 241 ms
17,164 KB
testcase_09 AC 670 ms
23,324 KB
testcase_10 AC 354 ms
14,012 KB
testcase_11 AC 874 ms
24,680 KB
testcase_12 AC 840 ms
21,500 KB
testcase_13 AC 175 ms
14,096 KB
testcase_14 AC 485 ms
23,708 KB
testcase_15 AC 829 ms
25,456 KB
testcase_16 AC 687 ms
26,912 KB
testcase_17 AC 254 ms
14,092 KB
testcase_18 AC 701 ms
16,652 KB
testcase_19 AC 697 ms
17,976 KB
testcase_20 AC 881 ms
21,100 KB
testcase_21 AC 470 ms
19,352 KB
testcase_22 AC 941 ms
27,312 KB
testcase_23 AC 256 ms
14,992 KB
testcase_24 AC 402 ms
19,376 KB
testcase_25 AC 754 ms
16,184 KB
testcase_26 AC 889 ms
22,008 KB
testcase_27 AC 1,026 ms
26,484 KB
testcase_28 AC 546 ms
15,756 KB
testcase_29 AC 700 ms
20,616 KB
testcase_30 AC 306 ms
20,548 KB
testcase_31 AC 568 ms
10,252 KB
testcase_32 AC 379 ms
16,272 KB
testcase_33 AC 684 ms
14,176 KB
testcase_34 AC 415 ms
45,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq
sys.setrecursionlimit(10**6)  # 再帰関数使う時有効


def countup(now, R):
    # if len(root[now]) == 1 and root[now][0] in used:
    #     count[root[now][0]] += count[now]+1
    #     return
    # if now in used:
    #     return
    for next_ in root[now]:
        if next_ == R:
            continue
        countup(next_, now)
    if now == R:
        return
    global count
    count[R] += count[now]


N, Q = map(int, input().split())
root = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)
count = [1]*N
countup(0, 0)

ans = 0
for i in range(Q):
    p, x = map(int, input().split())

    ans += count[p-1]*x
    print(ans)
0