結果

問題 No.1637 Easy Tree Query
ユーザー SidewaysOwlSidewaysOwl
提出日時 2021-08-07 07:41:17
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 449 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 81,440 KB
実行使用メモリ 91,752 KB
最終ジャッジ日時 2023-10-17 13:23:06
合計ジャッジ時間 15,206 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,404 KB
testcase_01 AC 37 ms
53,404 KB
testcase_02 AC 411 ms
88,308 KB
testcase_03 AC 36 ms
53,404 KB
testcase_04 AC 198 ms
82,556 KB
testcase_05 AC 365 ms
81,144 KB
testcase_06 AC 275 ms
80,384 KB
testcase_07 AC 186 ms
76,772 KB
testcase_08 AC 174 ms
81,456 KB
testcase_09 AC 329 ms
85,584 KB
testcase_10 AC 223 ms
79,040 KB
testcase_11 AC 421 ms
86,832 KB
testcase_12 AC 402 ms
84,532 KB
testcase_13 AC 155 ms
79,372 KB
testcase_14 AC 266 ms
86,172 KB
testcase_15 AC 398 ms
87,120 KB
testcase_16 AC 348 ms
88,520 KB
testcase_17 AC 182 ms
79,188 KB
testcase_18 AC 352 ms
80,992 KB
testcase_19 AC 347 ms
82,612 KB
testcase_20 AC 414 ms
84,516 KB
testcase_21 AC 265 ms
82,884 KB
testcase_22 AC 439 ms
88,528 KB
testcase_23 AC 177 ms
80,196 KB
testcase_24 AC 240 ms
82,844 KB
testcase_25 AC 364 ms
80,708 KB
testcase_26 AC 423 ms
84,692 KB
testcase_27 AC 480 ms
88,608 KB
testcase_28 AC 284 ms
80,312 KB
testcase_29 AC 353 ms
83,624 KB
testcase_30 AC 201 ms
83,464 KB
testcase_31 AC 276 ms
75,908 KB
testcase_32 AC 227 ms
80,776 KB
testcase_33 AC 341 ms
79,100 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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