結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-09-12 20:48:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 389 bytes |
| コンパイル時間 | 207 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 92,416 KB |
| 最終ジャッジ日時 | 2024-06-24 12:33:35 |
| 合計ジャッジ時間 | 12,066 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 RE * 1 |
ソースコード
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)
s=[0]*n
def dfs(now,before):
s[now]=1
for next in g[now]:
if next==before:
continue
dfs(next,now)
s[now]+=s[next]
dfs(0,-1)
ans=0
for _ in range(q):
p,x=map(int,input().split())
p-=1
ans+=s[p]*x
print(ans)