結果

問題 No.1637 Easy Tree Query
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-08-07 07:42:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 439 ms / 2,000 ms
コード長 491 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,724 KB
実行使用メモリ 176,248 KB
最終ジャッジ日時 2023-10-17 13:25:51
合計ジャッジ時間 13,012 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,712 KB
testcase_01 AC 36 ms
51,776 KB
testcase_02 AC 408 ms
88,572 KB
testcase_03 AC 64 ms
51,684 KB
testcase_04 AC 177 ms
82,680 KB
testcase_05 AC 359 ms
81,068 KB
testcase_06 AC 267 ms
80,312 KB
testcase_07 AC 186 ms
76,696 KB
testcase_08 AC 160 ms
81,388 KB
testcase_09 AC 298 ms
85,980 KB
testcase_10 AC 214 ms
78,972 KB
testcase_11 AC 380 ms
87,012 KB
testcase_12 AC 410 ms
84,928 KB
testcase_13 AC 148 ms
79,300 KB
testcase_14 AC 234 ms
86,324 KB
testcase_15 AC 366 ms
87,484 KB
testcase_16 AC 301 ms
88,936 KB
testcase_17 AC 179 ms
79,120 KB
testcase_18 AC 339 ms
80,924 KB
testcase_19 AC 336 ms
82,544 KB
testcase_20 AC 389 ms
84,772 KB
testcase_21 AC 243 ms
83,088 KB
testcase_22 AC 404 ms
88,856 KB
testcase_23 AC 178 ms
80,116 KB
testcase_24 AC 217 ms
83,048 KB
testcase_25 AC 360 ms
80,676 KB
testcase_26 AC 393 ms
85,028 KB
testcase_27 AC 439 ms
88,568 KB
testcase_28 AC 285 ms
80,244 KB
testcase_29 AC 325 ms
83,888 KB
testcase_30 AC 176 ms
83,720 KB
testcase_31 AC 287 ms
75,832 KB
testcase_32 AC 213 ms
80,704 KB
testcase_33 AC 343 ms
79,024 KB
testcase_34 AC 322 ms
176,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
n,q = map(int,input().split())
l = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)
ans = 0
ne = [1] + [0] * (n - 1)
def dfs(node):
    res = 1
    for nd in l[node]:
        if ne[nd] == 0:
            ne[nd] = 1
            res += dfs(nd)
    ne[node] = res
    return res
dfs(0)
for _ in range(q):
    p,x = map(int,input().split())
    ans += ne[p-1] * x
    print(ans)
0