結果
| 問題 | No.1637 Easy Tree Query |
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2021-08-07 07:41:17 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 449 bytes |
| 記録 | |
| コンパイル時間 | 504 ms |
| コンパイル使用メモリ | 84,880 KB |
| 実行使用メモリ | 98,024 KB |
| 最終ジャッジ日時 | 2026-04-06 06:33:07 |
| 合計ジャッジ時間 | 9,732 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 RE * 1 |
ソースコード
n,q = map(int,input().split())
l = [[] for _ in range(n)]
for _ in range(n-1):
a,b = map(int,input().split())
l[a-1].append(b-1)
l[b-1].append(a-1)
ans = 0
ne = [1] + [0] * (n - 1)
def dfs(node):
res = 1
for nd in l[node]:
if ne[nd] == 0:
ne[nd] = 1
res += dfs(nd)
ne[node] = res
return res
dfs(0)
for _ in range(q):
p,x = map(int,input().split())
ans += ne[p-1] * x
print(ans)
SidewaysOwl