結果

問題 No.1637 Easy Tree Query
ユーザー mkawa2mkawa2
提出日時 2021-08-06 21:25:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 507 ms / 2,000 ms
コード長 939 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 12,036 KB
実行使用メモリ 46,292 KB
最終ジャッジ日時 2023-10-17 04:48:40
合計ジャッジ時間 12,252 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,148 KB
testcase_01 AC 30 ms
10,148 KB
testcase_02 AC 437 ms
27,400 KB
testcase_03 AC 29 ms
10,148 KB
testcase_04 AC 189 ms
19,216 KB
testcase_05 AC 317 ms
16,612 KB
testcase_06 AC 217 ms
14,952 KB
testcase_07 AC 109 ms
10,596 KB
testcase_08 AC 149 ms
17,120 KB
testcase_09 AC 350 ms
23,280 KB
testcase_10 AC 164 ms
13,880 KB
testcase_11 AC 425 ms
24,636 KB
testcase_12 AC 392 ms
21,452 KB
testcase_13 AC 105 ms
14,144 KB
testcase_14 AC 294 ms
23,664 KB
testcase_15 AC 440 ms
25,408 KB
testcase_16 AC 400 ms
26,864 KB
testcase_17 AC 134 ms
14,144 KB
testcase_18 AC 302 ms
16,608 KB
testcase_19 AC 316 ms
17,928 KB
testcase_20 AC 408 ms
21,052 KB
testcase_21 AC 251 ms
19,308 KB
testcase_22 AC 494 ms
27,264 KB
testcase_23 AC 137 ms
15,212 KB
testcase_24 AC 219 ms
19,328 KB
testcase_25 AC 310 ms
16,140 KB
testcase_26 AC 402 ms
21,964 KB
testcase_27 AC 507 ms
26,436 KB
testcase_28 AC 242 ms
15,708 KB
testcase_29 AC 332 ms
20,572 KB
testcase_30 AC 197 ms
20,536 KB
testcase_31 AC 208 ms
10,268 KB
testcase_32 AC 192 ms
16,224 KB
testcase_33 AC 278 ms
13,880 KB
testcase_34 AC 267 ms
46,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

n,q=LI()
to=[[] for _ in range(n)]
for _ in range(n-1):
    u,v=LI1()
    to[u].append(v)
    to[v].append(u)

size=[1]*n

def dfs(u=0,par=-1):
    for v in to[u]:
        if v==par:continue
        dfs(v,u)
        size[u]+=size[v]

dfs()

cost=0
for _ in range(q):
    p,x=LI()
    p-=1
    cost+=size[p]*x
    print(cost)
0