結果

問題 No.1637 Easy Tree Query
ユーザー 👑 tamatotamato
提出日時 2021-08-06 21:22:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 104,148 KB
最終ジャッジ日時 2023-10-17 04:36:30
合計ジャッジ時間 7,005 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
55,856 KB
testcase_01 AC 35 ms
55,856 KB
testcase_02 AC 143 ms
104,148 KB
testcase_03 AC 33 ms
55,856 KB
testcase_04 AC 121 ms
89,428 KB
testcase_05 AC 126 ms
86,020 KB
testcase_06 AC 112 ms
83,476 KB
testcase_07 AC 81 ms
77,252 KB
testcase_08 AC 111 ms
87,296 KB
testcase_09 AC 165 ms
97,352 KB
testcase_10 AC 96 ms
81,760 KB
testcase_11 AC 170 ms
100,056 KB
testcase_12 AC 161 ms
92,320 KB
testcase_13 AC 86 ms
81,448 KB
testcase_14 AC 155 ms
98,160 KB
testcase_15 AC 187 ms
100,876 KB
testcase_16 AC 177 ms
103,744 KB
testcase_17 AC 100 ms
82,236 KB
testcase_18 AC 129 ms
85,924 KB
testcase_19 AC 139 ms
88,140 KB
testcase_20 AC 158 ms
92,720 KB
testcase_21 AC 126 ms
90,452 KB
testcase_22 AC 194 ms
103,784 KB
testcase_23 AC 105 ms
83,888 KB
testcase_24 AC 127 ms
90,528 KB
testcase_25 AC 130 ms
85,264 KB
testcase_26 AC 159 ms
93,600 KB
testcase_27 AC 196 ms
102,960 KB
testcase_28 AC 124 ms
84,852 KB
testcase_29 AC 151 ms
92,072 KB
testcase_30 AC 125 ms
91,844 KB
testcase_31 AC 74 ms
76,364 KB
testcase_32 AC 117 ms
85,616 KB
testcase_33 AC 116 ms
82,100 KB
testcase_34 AC 98 ms
99,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.buffer.readline

    N, Q = map(int, input().split())
    adj = [[] for _ in range(N+1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        adj[a].append(b)
        adj[b].append(a)

    que = deque()
    que.append(1)
    seen = [-1] * (N+1)
    seen[1] = 0
    par = [0] * (N+1)
    child = [[] for _ in range(N+1)]
    seq = []
    while que:
        v = que.popleft()
        seq.append(v)
        for u in adj[v]:
            if seen[u] == -1:
                seen[u] = seen[v] + 1
                par[u] = v
                child[v].append(u)
                que.append(u)
    seq.reverse()

    size = [1] * (N+1)
    for v in seq:
        for u in child[v]:
            size[v] += size[u]

    W = 0
    for _ in range(Q):
        p, x = map(int, input().split())
        W += x * size[p]
        print(W)


if __name__ == '__main__':
    main()
0