結果

問題 No.1637 Easy Tree Query
ユーザー wolgnikwolgnik
提出日時 2021-08-06 21:36:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 236 ms / 2,000 ms
コード長 597 bytes
コンパイル時間 1,241 ms
コンパイル使用メモリ 80,900 KB
実行使用メモリ 95,728 KB
最終ジャッジ日時 2023-10-17 05:02:25
合計ジャッジ時間 8,811 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,936 KB
testcase_01 AC 35 ms
52,936 KB
testcase_02 AC 168 ms
95,316 KB
testcase_03 AC 37 ms
53,188 KB
testcase_04 AC 125 ms
85,864 KB
testcase_05 AC 141 ms
82,744 KB
testcase_06 AC 114 ms
80,508 KB
testcase_07 AC 89 ms
75,860 KB
testcase_08 AC 113 ms
82,272 KB
testcase_09 AC 164 ms
90,860 KB
testcase_10 AC 106 ms
79,384 KB
testcase_11 AC 200 ms
92,768 KB
testcase_12 AC 188 ms
88,076 KB
testcase_13 AC 100 ms
79,572 KB
testcase_14 AC 166 ms
91,404 KB
testcase_15 AC 207 ms
93,328 KB
testcase_16 AC 224 ms
95,452 KB
testcase_17 AC 104 ms
79,736 KB
testcase_18 AC 148 ms
82,732 KB
testcase_19 AC 152 ms
84,236 KB
testcase_20 AC 178 ms
86,472 KB
testcase_21 AC 148 ms
85,872 KB
testcase_22 AC 225 ms
95,728 KB
testcase_23 AC 105 ms
80,824 KB
testcase_24 AC 140 ms
85,872 KB
testcase_25 AC 144 ms
82,000 KB
testcase_26 AC 180 ms
89,156 KB
testcase_27 AC 236 ms
95,168 KB
testcase_28 AC 135 ms
81,372 KB
testcase_29 AC 173 ms
87,240 KB
testcase_30 AC 143 ms
86,972 KB
testcase_31 AC 91 ms
75,444 KB
testcase_32 AC 125 ms
82,144 KB
testcase_33 AC 128 ms
79,664 KB
testcase_34 AC 108 ms
93,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
e = [[] for _ in range(N + 1)]
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

s = [1]
vis = [0] * (N + 1)
parent = [0] * (N + 1)
vis[1] = 1
order = []
while len(s):
  x = s.pop()
  order.append(x)
  for y in e[x]:
    if vis[y]: continue
    parent[y] = x
    vis[y] = 1
    s.append(y)

size = [1] * (N + 1)
order.reverse()
for y in order[: -1]:
  x = parent[y]
  size[x] += size[y]

res = 0
for _ in range(Q):
  x, v = map(int, input().split())
  res += size[x] * v
  print(res)
0