結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
player
|
| 提出日時 | 2023-12-20 00:42:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 504 bytes |
| コンパイル時間 | 161 ms |
| コンパイル使用メモリ | 82,040 KB |
| 実行使用メモリ | 92,304 KB |
| 最終ジャッジ日時 | 2024-09-27 09:04:34 |
| 合計ジャッジ時間 | 16,959 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 RE * 1 |
ソースコード
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
n,q = map(int,input().split())
edge = [[] for _ in range(n)]
for _ in range(n-1):
a,b = map(int,input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
cnt = [0]*n
def dfs(x,p):
ret = 1
for c in edge[x]:
if c == p:
continue
ret += dfs(c,x)
cnt[x] += ret
return ret
dfs(0,-1)
ans = 0
for _ in range(q):
p,x = map(int,input().split())
ans += cnt[p-1]*x
print(ans)
player