結果

問題 No.1637 Easy Tree Query
ユーザー raven7959raven7959
提出日時 2021-08-17 10:45:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 504 ms / 2,000 ms
コード長 495 bytes
コンパイル時間 253 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 212,096 KB
最終ジャッジ日時 2024-04-18 14:14:20
合計ジャッジ時間 13,743 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,840 KB
testcase_01 AC 45 ms
51,712 KB
testcase_02 AC 433 ms
89,216 KB
testcase_03 AC 42 ms
51,968 KB
testcase_04 AC 231 ms
83,456 KB
testcase_05 AC 406 ms
81,536 KB
testcase_06 AC 298 ms
80,512 KB
testcase_07 AC 211 ms
76,928 KB
testcase_08 AC 212 ms
82,816 KB
testcase_09 AC 375 ms
86,912 KB
testcase_10 AC 248 ms
79,616 KB
testcase_11 AC 454 ms
87,808 KB
testcase_12 AC 418 ms
85,248 KB
testcase_13 AC 169 ms
79,616 KB
testcase_14 AC 294 ms
87,040 KB
testcase_15 AC 427 ms
88,960 KB
testcase_16 AC 381 ms
89,728 KB
testcase_17 AC 206 ms
79,872 KB
testcase_18 AC 375 ms
81,792 KB
testcase_19 AC 372 ms
82,560 KB
testcase_20 AC 444 ms
84,864 KB
testcase_21 AC 289 ms
83,584 KB
testcase_22 AC 478 ms
90,112 KB
testcase_23 AC 206 ms
80,768 KB
testcase_24 AC 254 ms
83,840 KB
testcase_25 AC 382 ms
81,024 KB
testcase_26 AC 447 ms
85,760 KB
testcase_27 AC 504 ms
89,216 KB
testcase_28 AC 309 ms
81,152 KB
testcase_29 AC 384 ms
84,224 KB
testcase_30 AC 226 ms
84,352 KB
testcase_31 AC 287 ms
76,160 KB
testcase_32 AC 246 ms
81,408 KB
testcase_33 AC 364 ms
79,872 KB
testcase_34 AC 377 ms
212,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**9)
N,Q=map(int,input().split())
G=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(lambda x:int(x)-1,input().split())
  G[a].append(b)
  G[b].append(a)
seen=[False]*N
subtree_size=[1]*N
def dfs(G,v,p=-1):
  seen[v]=True 
  for nextv in G[v]:
    if nextv!=p:
      dfs(G,nextv,v)
  for c in G[v]:
    if c!=p:
      subtree_size[v]+=subtree_size[c]
dfs(G,0)
ans=0
for i in range(Q):
  p,x=map(int,input().split())
  ans+=x*subtree_size[p-1]
  print(ans)
0