結果

問題 No.1637 Easy Tree Query
ユーザー defilementdefilement
提出日時 2021-08-06 21:31:32
言語 PyPy3
(7.3.13)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 477 bytes
コンパイル時間 1,148 ms
コンパイル使用メモリ 81,652 KB
実行使用メモリ 92,508 KB
最終ジャッジ日時 2023-10-17 04:58:30
合計ジャッジ時間 13,559 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,564 KB
testcase_01 AC 37 ms
51,616 KB
testcase_02 AC 436 ms
89,216 KB
testcase_03 AC 38 ms
51,592 KB
testcase_04 AC 192 ms
82,780 KB
testcase_05 AC 369 ms
81,088 KB
testcase_06 AC 283 ms
80,344 KB
testcase_07 AC 193 ms
76,640 KB
testcase_08 AC 177 ms
81,400 KB
testcase_09 AC 316 ms
86,000 KB
testcase_10 AC 226 ms
78,988 KB
testcase_11 AC 404 ms
87,092 KB
testcase_12 AC 402 ms
84,596 KB
testcase_13 AC 159 ms
79,196 KB
testcase_14 AC 269 ms
86,804 KB
testcase_15 AC 381 ms
87,552 KB
testcase_16 AC 328 ms
89,100 KB
testcase_17 AC 188 ms
79,144 KB
testcase_18 AC 357 ms
80,940 KB
testcase_19 AC 349 ms
82,572 KB
testcase_20 AC 410 ms
84,836 KB
testcase_21 AC 267 ms
83,120 KB
testcase_22 AC 437 ms
89,036 KB
testcase_23 AC 188 ms
80,136 KB
testcase_24 AC 238 ms
83,088 KB
testcase_25 AC 376 ms
80,696 KB
testcase_26 AC 427 ms
85,052 KB
testcase_27 AC 484 ms
89,172 KB
testcase_28 AC 302 ms
80,268 KB
testcase_29 AC 356 ms
83,908 KB
testcase_30 AC 203 ms
83,740 KB
testcase_31 AC 285 ms
75,728 KB
testcase_32 AC 237 ms
80,728 KB
testcase_33 AC 354 ms
79,052 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n,q = map(int,input().split())

tree = [[]for _ in range(n)]
query = [0]*n

for _ in range(n-1):
    a,b = map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

visited = [False]*n

def visit(s):
    visited[s] = True
    ret = 1
    for w in tree[s]:
        if not visited[w]:
            ret += visit(w)
    query[s] = ret
    return ret

visit(0)
ans = 0
for _ in range(q):
    p,x = map(int,input().split())
    ans += x * query[p-1]
    print(ans)
0