結果

問題 No.1637 Easy Tree Query
ユーザー yudai1102jpyudai1102jp
提出日時 2021-08-06 23:51:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 782 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,992 KB
実行使用メモリ 813,516 KB
最終ジャッジ日時 2023-10-17 05:42:12
合計ジャッジ時間 24,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,156 KB
testcase_01 AC 29 ms
10,156 KB
testcase_02 AC 1,037 ms
27,396 KB
testcase_03 AC 29 ms
10,156 KB
testcase_04 AC 339 ms
19,196 KB
testcase_05 AC 773 ms
16,604 KB
testcase_06 AC 519 ms
14,780 KB
testcase_07 AC 263 ms
10,520 KB
testcase_08 AC 274 ms
17,112 KB
testcase_09 AC 718 ms
23,272 KB
testcase_10 AC 371 ms
13,756 KB
testcase_11 AC 943 ms
24,628 KB
testcase_12 AC 875 ms
21,452 KB
testcase_13 AC 185 ms
13,988 KB
testcase_14 AC 544 ms
23,656 KB
testcase_15 AC 914 ms
25,404 KB
testcase_16 AC 778 ms
26,860 KB
testcase_17 AC 271 ms
13,988 KB
testcase_18 AC 728 ms
16,600 KB
testcase_19 AC 736 ms
17,924 KB
testcase_20 AC 915 ms
21,048 KB
testcase_21 AC 519 ms
19,300 KB
testcase_22 AC 1,050 ms
27,260 KB
testcase_23 AC 272 ms
15,044 KB
testcase_24 AC 441 ms
19,324 KB
testcase_25 AC 775 ms
16,132 KB
testcase_26 AC 939 ms
21,956 KB
testcase_27 AC 1,105 ms
26,432 KB
testcase_28 AC 575 ms
15,704 KB
testcase_29 AC 753 ms
20,564 KB
testcase_30 AC 350 ms
20,492 KB
testcase_31 AC 571 ms
10,196 KB
testcase_32 AC 405 ms
16,220 KB
testcase_33 AC 710 ms
13,988 KB
testcase_34 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


def countup(now, R, used, count):
    # 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, used | set([now]), count)
    if now == R:
        return
    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, set(), count)

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

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