結果
問題 | No.1637 Easy Tree Query |
ユーザー |
|
提出日時 | 2021-11-10 01:15:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 285 ms / 2,000 ms |
コード長 | 613 bytes |
コンパイル時間 | 1,994 ms |
コンパイル使用メモリ | 169,168 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2024-11-19 10:02:10 |
合計ジャッジ時間 | 9,455 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define ll long long#define rep(i, n) for (int i = 0; i < (n); i++)#define P pair<int, int>vector<int> G[100005];int c[100000];void dfs(int v, int p = -1) {for (int nv : G[v]) {if (nv == p) continue;dfs(nv, v);c[v]++;c[v]+=c[nv];}}int main() {int n, q;cin >> n >> q;rep(i,n-1) {int a, b;cin >> a >> b;a--, b--;G[a].push_back(b);G[b].push_back(a);}dfs(0);ll ans = 0;rep(qi,q) {int p;ll x;cin >> p >> x;p--;ans += x*(c[p]+1);cout << ans << endl;}}