結果

問題 No.1637 Easy Tree Query
ユーザー 河野竜也河野竜也
提出日時 2021-09-12 20:47:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 389 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 25,932 KB
最終ジャッジ日時 2023-09-06 18:08:30
合計ジャッジ時間 20,310 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,784 KB
testcase_01 AC 13 ms
7,840 KB
testcase_02 AC 859 ms
25,388 KB
testcase_03 AC 13 ms
7,780 KB
testcase_04 AC 225 ms
17,180 KB
testcase_05 AC 612 ms
14,620 KB
testcase_06 AC 413 ms
12,908 KB
testcase_07 AC 213 ms
8,508 KB
testcase_08 AC 194 ms
15,136 KB
testcase_09 AC 521 ms
21,420 KB
testcase_10 AC 285 ms
12,020 KB
testcase_11 AC 709 ms
22,812 KB
testcase_12 AC 684 ms
19,564 KB
testcase_13 AC 128 ms
12,256 KB
testcase_14 AC 367 ms
21,748 KB
testcase_15 AC 650 ms
23,536 KB
testcase_16 AC 534 ms
24,972 KB
testcase_17 AC 201 ms
12,132 KB
testcase_18 AC 595 ms
14,688 KB
testcase_19 AC 565 ms
16,036 KB
testcase_20 AC 713 ms
19,200 KB
testcase_21 AC 369 ms
17,420 KB
testcase_22 AC 771 ms
25,408 KB
testcase_23 AC 211 ms
13,140 KB
testcase_24 AC 311 ms
17,380 KB
testcase_25 AC 610 ms
14,148 KB
testcase_26 AC 737 ms
19,944 KB
testcase_27 AC 843 ms
24,632 KB
testcase_28 AC 453 ms
13,816 KB
testcase_29 AC 565 ms
18,588 KB
testcase_30 AC 234 ms
18,488 KB
testcase_31 AC 473 ms
7,860 KB
testcase_32 AC 306 ms
14,220 KB
testcase_33 AC 587 ms
11,980 KB
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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