結果

問題 No.1637 Easy Tree Query
ユーザー 河野竜也
提出日時 2021-09-12 20:47:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 389 bytes
コンパイル時間 672 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 28,288 KB
最終ジャッジ日時 2024-06-24 12:32:45
合計ジャッジ時間 25,795 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32 RE * 1
権限があれば一括ダウンロードができます

ソースコード

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