結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-08-06 21:36:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 2,000 ms |
| コード長 | 840 bytes |
| コンパイル時間 | 961 ms |
| コンパイル使用メモリ | 86,240 KB |
| 最終ジャッジ日時 | 2025-01-23 14:47:39 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
ソースコード
#include <iostream>
#include <vector>
#include <utility>
#include <atcoder/maxflow>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
#define rep(i,n) for(int i=0; i<(n); i++)
int N, Q;
vector<vector<int>> E;
vector<int> Z;
vector<i64> A;
int main(){
cin >> N >> Q;
E.resize(N);
rep(i,N-1){
int u,v; cin >> u >> v; u--; v--;
E[u].push_back(v);
E[v].push_back(u);
}
Z.assign(N,1);
auto dfs = [&](int p,int pre,auto dfs)->void{
for(int e : E[p]) if(pre != e){
dfs(e,p,dfs);
Z[p] += Z[e];
}
};
dfs(0,-1,dfs);
i64 ans = 0;
rep(i,Q){
int p; i64 x; cin >> p >> x; p--;
ans += x * Z[p];
cout << ans << "\n";
}
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia