結果

問題 No.1637 Easy Tree Query
ユーザー KudeKude
提出日時 2021-08-06 21:26:08
言語 PyPy3
(7.3.13)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 442 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 91,832 KB
最終ジャッジ日時 2023-10-17 04:49:48
合計ジャッジ時間 12,983 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,500 KB
testcase_01 AC 37 ms
53,500 KB
testcase_02 AC 415 ms
88,264 KB
testcase_03 AC 37 ms
51,804 KB
testcase_04 AC 200 ms
82,444 KB
testcase_05 AC 378 ms
80,992 KB
testcase_06 AC 282 ms
80,188 KB
testcase_07 AC 195 ms
76,828 KB
testcase_08 AC 180 ms
81,292 KB
testcase_09 AC 344 ms
86,288 KB
testcase_10 AC 235 ms
79,020 KB
testcase_11 AC 433 ms
86,564 KB
testcase_12 AC 414 ms
84,296 KB
testcase_13 AC 159 ms
79,216 KB
testcase_14 AC 278 ms
86,000 KB
testcase_15 AC 415 ms
87,080 KB
testcase_16 AC 356 ms
88,276 KB
testcase_17 AC 198 ms
79,168 KB
testcase_18 AC 357 ms
80,856 KB
testcase_19 AC 360 ms
82,172 KB
testcase_20 AC 427 ms
84,216 KB
testcase_21 AC 276 ms
82,812 KB
testcase_22 AC 463 ms
88,476 KB
testcase_23 AC 188 ms
80,080 KB
testcase_24 AC 246 ms
82,892 KB
testcase_25 AC 381 ms
80,532 KB
testcase_26 AC 439 ms
84,752 KB
testcase_27 AC 497 ms
88,236 KB
testcase_28 AC 309 ms
80,392 KB
testcase_29 AC 361 ms
84,292 KB
testcase_30 AC 205 ms
83,592 KB
testcase_31 AC 286 ms
75,960 KB
testcase_32 AC 235 ms
80,668 KB
testcase_33 AC 363 ms
79,100 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp = [0] * n
def dfs(u, p=-1):
    dp[u] = 1
    for v in to[u]:
        if v == p:
            continue
        dfs(v, u)
        dp[u] += dp[v]

dfs(0)
ans = 0

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