結果

問題 No.1637 Easy Tree Query
ユーザー c-yanc-yan
提出日時 2021-08-06 22:05:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 674 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 11,988 KB
実行使用メモリ 46,172 KB
最終ジャッジ日時 2023-10-17 03:28:47
合計ジャッジ時間 8,650 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 AC 24 ms
10,020 KB
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 WA -
testcase_32 RE -
testcase_33 WA -
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit, stdin

readline = stdin.readline
setrecursionlimit(10 ** 6)

N, Q = map(int, readline().split())

links = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, readline().split())
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)

visited = [False] * N
subnodes = [0] * N
def f(i):
    visited[i] = True
    result = 1
    for j in links[i]:
        if visited[j]:
            continue
        result += f(j)
    subnodes[i] = result
    return result

f(0)

result = []
t = 0
for _ in range(N - 1):
    p, x = map(int, readline().split())
    t += subnodes[p - 1] * x
    result.append(t)
print(*result, sep='\n')
0