結果

問題 No.1637 Easy Tree Query
ユーザー 河野竜也河野竜也
提出日時 2021-09-12 20:48:56
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 389 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 95,864 KB
最終ジャッジ日時 2023-09-06 18:09:25
合計ジャッジ時間 12,524 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,212 KB
testcase_01 AC 61 ms
71,392 KB
testcase_02 AC 363 ms
89,972 KB
testcase_03 AC 59 ms
71,132 KB
testcase_04 AC 177 ms
84,072 KB
testcase_05 AC 347 ms
82,048 KB
testcase_06 AC 251 ms
81,564 KB
testcase_07 AC 192 ms
77,968 KB
testcase_08 AC 170 ms
83,660 KB
testcase_09 AC 273 ms
87,856 KB
testcase_10 AC 197 ms
80,428 KB
testcase_11 AC 335 ms
87,940 KB
testcase_12 AC 351 ms
85,788 KB
testcase_13 AC 150 ms
80,628 KB
testcase_14 AC 222 ms
87,704 KB
testcase_15 AC 329 ms
88,472 KB
testcase_16 AC 290 ms
89,688 KB
testcase_17 AC 172 ms
80,492 KB
testcase_18 AC 295 ms
82,532 KB
testcase_19 AC 293 ms
83,304 KB
testcase_20 AC 351 ms
86,040 KB
testcase_21 AC 223 ms
84,104 KB
testcase_22 AC 360 ms
90,272 KB
testcase_23 AC 173 ms
81,044 KB
testcase_24 AC 201 ms
84,212 KB
testcase_25 AC 319 ms
82,020 KB
testcase_26 AC 355 ms
86,208 KB
testcase_27 AC 385 ms
89,964 KB
testcase_28 AC 254 ms
81,620 KB
testcase_29 AC 287 ms
85,612 KB
testcase_30 AC 174 ms
85,660 KB
testcase_31 AC 264 ms
78,092 KB
testcase_32 AC 205 ms
82,276 KB
testcase_33 AC 318 ms
80,484 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