結果

問題 No.1637 Easy Tree Query
ユーザー yudai1102jp
提出日時 2021-08-06 23:51:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
MLE  
実行時間 -
コード長 782 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 817,792 KB
最終ジャッジ日時 2024-09-17 04:22:19
合計ジャッジ時間 26,706 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

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