結果

問題 No.1637 Easy Tree Query
ユーザー yansi819yansi819
提出日時 2024-04-25 11:16:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 5,266 ms
コンパイル使用メモリ 256,764 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2024-04-25 11:16:53
合計ジャッジ時間 12,319 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 238 ms
11,008 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 53 ms
7,168 KB
testcase_05 AC 222 ms
6,016 KB
testcase_06 AC 127 ms
5,376 KB
testcase_07 AC 75 ms
5,376 KB
testcase_08 AC 43 ms
6,272 KB
testcase_09 AC 147 ms
9,088 KB
testcase_10 AC 86 ms
5,376 KB
testcase_11 AC 206 ms
9,728 KB
testcase_12 AC 203 ms
8,064 KB
testcase_13 AC 31 ms
5,376 KB
testcase_14 AC 86 ms
9,216 KB
testcase_15 AC 188 ms
9,856 KB
testcase_16 AC 140 ms
10,752 KB
testcase_17 AC 57 ms
5,376 KB
testcase_18 AC 182 ms
6,016 KB
testcase_19 AC 178 ms
6,656 KB
testcase_20 AC 257 ms
7,936 KB
testcase_21 AC 106 ms
7,296 KB
testcase_22 AC 245 ms
10,752 KB
testcase_23 AC 58 ms
5,376 KB
testcase_24 AC 86 ms
7,552 KB
testcase_25 AC 203 ms
5,760 KB
testcase_26 AC 235 ms
8,448 KB
testcase_27 AC 242 ms
10,496 KB
testcase_28 AC 139 ms
5,632 KB
testcase_29 AC 183 ms
7,808 KB
testcase_30 AC 48 ms
7,808 KB
testcase_31 AC 162 ms
5,376 KB
testcase_32 AC 87 ms
5,888 KB
testcase_33 AC 208 ms
5,376 KB
testcase_34 AC 65 ms
14,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

vector<vector<ll>> g;
vector<ll> cnt;
vector<ll> B;

void f(int i) {
  B[i] = 1;
  for (ll j: g[i]) {
    if (B[j] == 0) {
      f(j);
      cnt[i] += cnt[j];
    }
  }
}
int main() {
  ll N, Q, a, b, ans = 0, p, x;
  cin >> N >> Q;
  g.resize(N);
  cnt.resize(N);
  B.resize(N);
  for (int i = 0; i < N - 1; i++) {
    cnt[i] = 1;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cnt[N - 1] = 1;
  f(0);
  for (int i = 0; i < Q; i++) {
    cin >> p >> x;
    p--;
    ans += cnt[p] * x;
    cout << ans << endl;
  }
  return 0;
}
0