結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2021-08-07 07:41:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 449 bytes |
| コンパイル時間 | 488 ms |
| コンパイル使用メモリ | 81,968 KB |
| 実行使用メモリ | 92,264 KB |
| 最終ジャッジ日時 | 2024-09-17 11:22:45 |
| 合計ジャッジ時間 | 13,610 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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