結果

問題 No.1637 Easy Tree Query
ユーザー 河野竜也河野竜也
提出日時 2021-09-12 20:50:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 963 ms / 2,000 ms
コード長 431 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 10,784 KB
実行使用メモリ 44,356 KB
最終ジャッジ日時 2023-09-06 18:11:23
合計ジャッジ時間 21,126 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,872 KB
testcase_01 AC 16 ms
7,736 KB
testcase_02 AC 957 ms
25,420 KB
testcase_03 AC 15 ms
7,912 KB
testcase_04 AC 260 ms
17,244 KB
testcase_05 AC 711 ms
14,624 KB
testcase_06 AC 478 ms
12,844 KB
testcase_07 AC 247 ms
8,508 KB
testcase_08 AC 210 ms
15,204 KB
testcase_09 AC 610 ms
21,280 KB
testcase_10 AC 336 ms
12,060 KB
testcase_11 AC 823 ms
22,900 KB
testcase_12 AC 788 ms
19,472 KB
testcase_13 AC 153 ms
12,032 KB
testcase_14 AC 456 ms
21,804 KB
testcase_15 AC 784 ms
23,416 KB
testcase_16 AC 620 ms
25,100 KB
testcase_17 AC 234 ms
12,256 KB
testcase_18 AC 670 ms
14,588 KB
testcase_19 AC 663 ms
15,972 KB
testcase_20 AC 813 ms
19,052 KB
testcase_21 AC 446 ms
17,288 KB
testcase_22 AC 945 ms
25,208 KB
testcase_23 AC 242 ms
13,252 KB
testcase_24 AC 388 ms
17,280 KB
testcase_25 AC 722 ms
14,148 KB
testcase_26 AC 842 ms
19,952 KB
testcase_27 AC 963 ms
24,744 KB
testcase_28 AC 528 ms
13,804 KB
testcase_29 AC 673 ms
18,712 KB
testcase_30 AC 263 ms
18,516 KB
testcase_31 AC 552 ms
7,848 KB
testcase_32 AC 355 ms
14,184 KB
testcase_33 AC 674 ms
12,168 KB
testcase_34 AC 386 ms
44,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)
n,q=map(int,input().split())
g=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  g[a].append(b)
  g[b].append(a)
s=[0]*n
def dfs(now,before):
  s[now]=1
  for next in g[now]:
    if next==before:
      continue
    dfs(next,now)
    s[now]+=s[next]
dfs(0,-1)
ans=0
for _ in range(q):
  p,x=map(int,input().split())
  p-=1
  ans+=s[p]*x
  print(ans)
0