結果

問題 No.1637 Easy Tree Query
ユーザー yudai1102jpyudai1102jp
提出日時 2021-08-06 22:26:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 727 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 11,944 KB
実行使用メモリ 48,920 KB
最終ジャッジ日時 2023-10-17 05:12:36
合計ジャッジ時間 23,525 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,012 KB
testcase_01 AC 29 ms
10,012 KB
testcase_02 AC 1,043 ms
28,056 KB
testcase_03 AC 30 ms
10,012 KB
testcase_04 AC 353 ms
19,712 KB
testcase_05 AC 819 ms
17,792 KB
testcase_06 AC 541 ms
15,800 KB
testcase_07 AC 271 ms
10,480 KB
testcase_08 AC 278 ms
17,508 KB
testcase_09 AC 743 ms
24,724 KB
testcase_10 AC 387 ms
14,612 KB
testcase_11 AC 976 ms
26,872 KB
testcase_12 AC 920 ms
23,320 KB
testcase_13 AC 188 ms
14,440 KB
testcase_14 AC 538 ms
24,580 KB
testcase_15 AC 925 ms
27,384 KB
testcase_16 AC 771 ms
28,576 KB
testcase_17 AC 278 ms
14,700 KB
testcase_18 AC 754 ms
17,788 KB
testcase_19 AC 769 ms
19,112 KB
testcase_20 AC 959 ms
22,764 KB
testcase_21 AC 533 ms
20,488 KB
testcase_22 AC 1,099 ms
29,504 KB
testcase_23 AC 285 ms
15,680 KB
testcase_24 AC 452 ms
20,248 KB
testcase_25 AC 806 ms
17,056 KB
testcase_26 AC 963 ms
23,936 KB
testcase_27 AC 1,141 ms
28,940 KB
testcase_28 AC 605 ms
16,628 KB
testcase_29 AC 797 ms
22,012 KB
testcase_30 AC 345 ms
20,936 KB
testcase_31 AC 593 ms
10,072 KB
testcase_32 AC 422 ms
17,144 KB
testcase_33 AC 739 ms
14,852 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def countup(now, R, used, count):
    # if len(root[now]) == 1 and root[now][0] in used:
    #     count[root[now][0]] += count[now]+1
    #     return
    if now in used:
        return
    for next_ in root[now]:
        if next_ == R:
            continue
        countup(next_, now, used | set([now]), count)
    if now == R:
        return
    count[R] += count[now]


N, Q = map(int, input().split())
root = [[] for i in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)
count = [1]*N
countup(0, 0, set(), count)
cost = [0]*N
ans = 0
for i in range(Q):
    p, x = map(int, input().split())
    cost[p-1] += x
    ans += count[p-1]*x
    print(ans)
0