結果

問題 No.1637 Easy Tree Query
ユーザー prd_xxxprd_xxx
提出日時 2021-08-06 23:07:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 616 bytes
コンパイル時間 430 ms
コンパイル使用メモリ 12,064 KB
実行使用メモリ 51,716 KB
最終ジャッジ日時 2023-10-17 04:37:38
合計ジャッジ時間 13,245 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,092 KB
testcase_01 AC 30 ms
10,092 KB
testcase_02 AC 453 ms
50,800 KB
testcase_03 AC 29 ms
10,092 KB
testcase_04 AC 202 ms
27,028 KB
testcase_05 AC 328 ms
34,060 KB
testcase_06 AC 230 ms
26,448 KB
testcase_07 AC 112 ms
15,540 KB
testcase_08 AC 161 ms
23,548 KB
testcase_09 AC 377 ms
39,892 KB
testcase_10 AC 169 ms
22,064 KB
testcase_11 AC 456 ms
46,284 KB
testcase_12 AC 415 ms
41,364 KB
testcase_13 AC 109 ms
18,312 KB
testcase_14 AC 304 ms
36,284 KB
testcase_15 AC 455 ms
45,900 KB
testcase_16 AC 423 ms
44,612 KB
testcase_17 AC 136 ms
20,168 KB
testcase_18 AC 313 ms
32,900 KB
testcase_19 AC 329 ms
34,296 KB
testcase_20 AC 427 ms
41,920 KB
testcase_21 AC 263 ms
31,304 KB
testcase_22 AC 529 ms
50,988 KB
testcase_23 AC 146 ms
21,332 KB
testcase_24 AC 241 ms
29,688 KB
testcase_25 AC 333 ms
33,308 KB
testcase_26 AC 440 ms
43,440 KB
testcase_27 AC 538 ms
51,716 KB
testcase_28 AC 256 ms
28,548 KB
testcase_29 AC 365 ms
37,540 KB
testcase_30 AC 219 ms
28,668 KB
testcase_31 AC 215 ms
20,060 KB
testcase_32 AC 203 ms
25,532 KB
testcase_33 AC 295 ms
29,816 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N,Q = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
PX = [tuple(map(int,input().split())) for i in range(Q)]

es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

cs = [0] * N
def dfs(v,p=-1):
    if len(es[v])==1:
        cs[v] = 2 if v==0 else 1
        return cs[v]
    ret = 1
    for to in es[v]:
        if to==p: continue
        ret += dfs(to,v)
    cs[v] = ret
    return ret
dfs(0)

ans = 0
for p,x in PX:
    p -= 1
    ans += cs[p] * x
    print(ans)
0