結果

問題 No.1637 Easy Tree Query
ユーザー sotanishysotanishy
提出日時 2021-08-06 21:25:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 81,812 KB
実行使用メモリ 96,200 KB
最終ジャッジ日時 2023-10-17 04:44:59
合計ジャッジ時間 7,470 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,476 KB
testcase_01 AC 39 ms
53,476 KB
testcase_02 AC 159 ms
87,964 KB
testcase_03 AC 35 ms
53,476 KB
testcase_04 AC 123 ms
82,280 KB
testcase_05 AC 142 ms
80,568 KB
testcase_06 AC 123 ms
79,420 KB
testcase_07 AC 96 ms
76,616 KB
testcase_08 AC 118 ms
80,972 KB
testcase_09 AC 170 ms
85,292 KB
testcase_10 AC 111 ms
78,740 KB
testcase_11 AC 190 ms
86,380 KB
testcase_12 AC 168 ms
84,044 KB
testcase_13 AC 97 ms
78,772 KB
testcase_14 AC 149 ms
85,460 KB
testcase_15 AC 182 ms
86,772 KB
testcase_16 AC 186 ms
88,048 KB
testcase_17 AC 102 ms
78,828 KB
testcase_18 AC 135 ms
80,564 KB
testcase_19 AC 143 ms
81,552 KB
testcase_20 AC 168 ms
84,024 KB
testcase_21 AC 134 ms
82,508 KB
testcase_22 AC 203 ms
88,312 KB
testcase_23 AC 105 ms
79,456 KB
testcase_24 AC 127 ms
82,536 KB
testcase_25 AC 136 ms
80,524 KB
testcase_26 AC 170 ms
84,464 KB
testcase_27 AC 202 ms
88,040 KB
testcase_28 AC 124 ms
79,912 KB
testcase_29 AC 155 ms
83,428 KB
testcase_30 AC 132 ms
83,260 KB
testcase_31 AC 87 ms
75,740 KB
testcase_32 AC 116 ms
80,416 KB
testcase_33 AC 129 ms
78,784 KB
testcase_34 AC 117 ms
96,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(lambda x: int(x) - 1, input().split())
    G[a].append(b)
    G[b].append(a)
size = [1] * N
st = [(0, -1, 0)]
while st:
    v, p, t = st.pop()
    if t == 0:
        st.append((v, p, 1))
        for c in G[v]:
            if c != p:
                st.append((c, v, 0))
    else:
        for c in G[v]:
            if c != p:
                size[v] += size[c]
ans = 0
for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans += size[p] * x
    print(ans)
0