結果

問題 No.1637 Easy Tree Query
ユーザー sangonanasangonana
提出日時 2021-08-06 21:31:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 879 ms / 2,000 ms
コード長 437 bytes
コンパイル時間 902 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 46,288 KB
最終ジャッジ日時 2023-10-17 04:59:35
合計ジャッジ時間 19,118 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,164 KB
testcase_01 AC 24 ms
10,164 KB
testcase_02 AC 879 ms
28,204 KB
testcase_03 AC 25 ms
10,164 KB
testcase_04 AC 240 ms
19,608 KB
testcase_05 AC 643 ms
16,884 KB
testcase_06 AC 421 ms
15,156 KB
testcase_07 AC 220 ms
10,560 KB
testcase_08 AC 201 ms
17,392 KB
testcase_09 AC 541 ms
23,816 KB
testcase_10 AC 312 ms
14,048 KB
testcase_11 AC 863 ms
25,436 KB
testcase_12 AC 833 ms
21,968 KB
testcase_13 AC 150 ms
14,324 KB
testcase_14 AC 395 ms
24,200 KB
testcase_15 AC 690 ms
25,948 KB
testcase_16 AC 555 ms
27,668 KB
testcase_17 AC 220 ms
14,320 KB
testcase_18 AC 673 ms
16,880 KB
testcase_19 AC 582 ms
18,204 KB
testcase_20 AC 739 ms
21,592 KB
testcase_21 AC 474 ms
19,844 KB
testcase_22 AC 842 ms
28,068 KB
testcase_23 AC 214 ms
15,392 KB
testcase_24 AC 342 ms
19,868 KB
testcase_25 AC 648 ms
16,412 KB
testcase_26 AC 778 ms
22,500 KB
testcase_27 AC 867 ms
27,240 KB
testcase_28 AC 470 ms
15,984 KB
testcase_29 AC 641 ms
20,844 KB
testcase_30 AC 253 ms
20,968 KB
testcase_31 AC 490 ms
10,212 KB
testcase_32 AC 318 ms
16,500 KB
testcase_33 AC 587 ms
14,312 KB
testcase_34 AC 351 ms
46,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

n,q=map(int,input().split())
node=[[]for i in range(n)]
for i in range(n-1):
	a,b=map(int,input().split())
	node[a-1].append(b-1)
	node[b-1].append(a-1)

cnt=[0]*n
visited=[0]*n
visited[0]=1
def dfs(x):
	now=1
	for y in node[x]:
		if visited[y]==0:
			visited[y]=1
			now+=dfs(y)
	cnt[x]=now
	return now

dfs(0)

ans=0
for i in range(q):
	p,x=map(int,input().split())
	ans+=cnt[p-1]*x
	print(ans)
0