結果

問題 No.1637 Easy Tree Query
ユーザー prd_xxxprd_xxx
提出日時 2021-08-06 23:04:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 598 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 11,996 KB
実行使用メモリ 51,680 KB
最終ジャッジ日時 2023-10-17 04:32:36
合計ジャッジ時間 10,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,056 KB
testcase_01 AC 26 ms
10,056 KB
testcase_02 AC 396 ms
50,784 KB
testcase_03 WA -
testcase_04 AC 158 ms
26,932 KB
testcase_05 AC 288 ms
34,024 KB
testcase_06 AC 190 ms
26,564 KB
testcase_07 AC 96 ms
15,476 KB
testcase_08 AC 120 ms
23,540 KB
testcase_09 AC 300 ms
39,968 KB
testcase_10 AC 141 ms
22,028 KB
testcase_11 AC 364 ms
46,132 KB
testcase_12 AC 327 ms
41,456 KB
testcase_13 AC 85 ms
18,276 KB
testcase_14 AC 233 ms
36,088 KB
testcase_15 AC 355 ms
45,756 KB
testcase_16 AC 320 ms
44,576 KB
testcase_17 AC 110 ms
20,132 KB
testcase_18 AC 257 ms
32,864 KB
testcase_19 AC 263 ms
34,260 KB
testcase_20 AC 338 ms
41,884 KB
testcase_21 AC 203 ms
31,128 KB
testcase_22 AC 408 ms
51,060 KB
testcase_23 AC 114 ms
21,296 KB
testcase_24 AC 180 ms
29,588 KB
testcase_25 AC 267 ms
33,420 KB
testcase_26 AC 360 ms
43,476 KB
testcase_27 AC 428 ms
51,680 KB
testcase_28 AC 207 ms
28,512 KB
testcase_29 AC 281 ms
37,536 KB
testcase_30 AC 158 ms
28,572 KB
testcase_31 AC 184 ms
20,024 KB
testcase_32 AC 160 ms
25,496 KB
testcase_33 AC 243 ms
29,780 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] = 1
        return 1
    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