結果

問題 No.1637 Easy Tree Query
ユーザー googol_S0googol_S0
提出日時 2021-08-06 21:22:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 436 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 81,732 KB
実行使用メモリ 178,224 KB
最終ジャッジ日時 2023-10-17 04:36:01
合計ジャッジ時間 7,702 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,384 KB
testcase_01 AC 37 ms
53,384 KB
testcase_02 AC 153 ms
87,828 KB
testcase_03 AC 38 ms
53,384 KB
testcase_04 AC 129 ms
82,052 KB
testcase_05 AC 141 ms
80,552 KB
testcase_06 AC 116 ms
79,220 KB
testcase_07 AC 82 ms
76,016 KB
testcase_08 AC 113 ms
80,780 KB
testcase_09 AC 176 ms
85,140 KB
testcase_10 AC 103 ms
78,516 KB
testcase_11 AC 200 ms
86,140 KB
testcase_12 AC 174 ms
83,756 KB
testcase_13 AC 97 ms
78,656 KB
testcase_14 AC 169 ms
85,284 KB
testcase_15 AC 197 ms
86,540 KB
testcase_16 AC 206 ms
87,704 KB
testcase_17 AC 99 ms
78,668 KB
testcase_18 AC 135 ms
80,312 KB
testcase_19 AC 143 ms
81,276 KB
testcase_20 AC 170 ms
83,496 KB
testcase_21 AC 137 ms
82,236 KB
testcase_22 AC 211 ms
87,940 KB
testcase_23 AC 100 ms
79,440 KB
testcase_24 AC 130 ms
82,260 KB
testcase_25 AC 129 ms
80,000 KB
testcase_26 AC 169 ms
84,204 KB
testcase_27 AC 210 ms
87,628 KB
testcase_28 AC 118 ms
79,724 KB
testcase_29 AC 152 ms
83,088 KB
testcase_30 AC 129 ms
82,988 KB
testcase_31 AC 84 ms
75,572 KB
testcase_32 AC 116 ms
80,140 KB
testcase_33 AC 115 ms
78,600 KB
testcase_34 AC 331 ms
178,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
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)
DP=[1]*N
def dfs(n,p):
  for i in range(len(G[n])):
    if G[n][i]!=p:
      DP[n]+=dfs(G[n][i],n)
  return DP[n]

dfs(0,-1)
ANS=0
for i in range(Q):
  p,x=map(int,input().split())
  ANS+=DP[p-1]*x
  print(ANS)
0