結果

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

ソースコード

diff #

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)
cost = [0]*N
ans = 0
for i in range(Q):
    p, x = map(int, input().split())
    cost[p-1] += x
    ans += count[p-1]*x
    print(ans)
0