結果
問題 | No.1637 Easy Tree Query |
ユーザー |
![]() |
提出日時 | 2024-03-16 17:36:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 306 ms / 2,000 ms |
コード長 | 749 bytes |
コンパイル時間 | 2,195 ms |
コンパイル使用メモリ | 194,908 KB |
最終ジャッジ日時 | 2025-02-20 06:56:05 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 33 |
ソースコード
#include <bits/stdc++.h>#ifdef LOCAL#include "./debug.cpp"#else#define debug(...)#define print_line#endifusing namespace std;using ll = long long;int N, Q;vector<int> G[1 << 17];int C[1 << 17];void dfs(int now, int pre) {for (int nxt : G[now]) {if (nxt != pre) {dfs(nxt, now);C[now] += C[nxt];}}C[now]++;}int main() {cin >> N >> Q;for (int i = 0; i < N - 1; i++) {int a, b;cin >> a >> b;a--;b--;G[a].push_back(b);G[b].push_back(a);}dfs(0, 0);ll now = 0;while (Q--) {int p, x;cin >> p >> x;p--;now += 1ll * C[p] * x;cout << now << '\n';}}