結果
| 問題 |
No.1637 Easy Tree Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 23:18:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 265 ms / 2,000 ms |
| コード長 | 1,307 bytes |
| コンパイル時間 | 3,522 ms |
| コンパイル使用メモリ | 231,924 KB |
| 実行使用メモリ | 17,280 KB |
| 最終ジャッジ日時 | 2024-09-17 03:40:19 |
| 合計ジャッジ時間 | 10,746 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define frep(i,a,b) for (int i = (a); i <= (b); ++i)
#define all(x) (x).begin(),(x).end()
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define debug(x) cout << #x << ": " << x << endl;
typedef long long ll;
using P = pair<ll,ll>;
using P2 = pair<ll,P>;
using mint = modint1000000007;
#define INF 1001001001
#define LINF (1LL<<60)
#define F first
#define S second
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }
int n, q;
vector<vector<int>> to;
vector<ll> h;
void dfs(int v, int p = -1) {
h[v] = 1;
for (int u : to[v]) {
if (u == p) continue;
dfs(u, v);
h[v] += h[u];
}
return;
}
int main() {
cin >> n >> q;
to.resize(n);
rep(i, n-1) {
int a, b;
cin >> a >> b;
to[a-1].push_back(b-1);
to[b-1].push_back(a-1);
}
h.resize(n);
dfs(0);
ll ans = 0;
rep(i, q) {
ll p, x;
cin >> p >> x;
ans += h[p-1] * x;
cout << ans << endl;
}
}