結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2021-12-27 10:07:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 271 ms / 2,000 ms |
| コード長 | 634 bytes |
| コンパイル時間 | 671 ms |
| コンパイル使用メモリ | 70,812 KB |
| 実行使用メモリ | 17,664 KB |
| 最終ジャッジ日時 | 2024-09-25 03:42:14 |
| 合計ジャッジ時間 | 9,379 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
ソースコード
#include <iostream>
#include <vector>
using namespace std;
long long child[100001];
bool lck[100001];
vector<int> V[100001];
int dfs(int nw,int n){
int ret = 0;
for(int i = 0; V[nw].size() > i; i++){
if(lck[V[nw][i]])continue;
lck[V[nw][i]] = true;
ret += dfs(V[nw][i],n);
}
return child[nw] = ret+1;
}
int main(){
int n,q;cin>>n>>q;
for(int i = 0; n-1 > i; i++){
int s,t;cin>>s>>t;
s--;t--;
V[s].push_back(t);
V[t].push_back(s);
}
lck[0] = true;
dfs(0,n);
long long ans = 0;
for(int i = 0; q > i; i++){
int p,x;cin>>p>>x;p--;
ans += child[p]*x;
cout << ans << endl;
}
}