結果

問題 No.1637 Easy Tree Query
ユーザー Today03Today03
提出日時 2024-03-16 17:36:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 2,073 ms
コンパイル使用メモリ 203,444 KB
実行使用メモリ 17,888 KB
最終ジャッジ日時 2024-03-16 17:37:10
合計ジャッジ時間 11,441 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 267 ms
10,080 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 58 ms
8,416 KB
testcase_05 AC 223 ms
7,904 KB
testcase_06 AC 149 ms
7,520 KB
testcase_07 AC 79 ms
6,676 KB
testcase_08 AC 48 ms
8,032 KB
testcase_09 AC 189 ms
9,312 KB
testcase_10 AC 100 ms
7,392 KB
testcase_11 AC 242 ms
9,568 KB
testcase_12 AC 233 ms
8,928 KB
testcase_13 AC 36 ms
7,392 KB
testcase_14 AC 98 ms
9,312 KB
testcase_15 AC 208 ms
9,696 KB
testcase_16 AC 150 ms
10,080 KB
testcase_17 AC 67 ms
7,392 KB
testcase_18 AC 205 ms
7,904 KB
testcase_19 AC 197 ms
8,160 KB
testcase_20 AC 240 ms
8,800 KB
testcase_21 AC 118 ms
8,416 KB
testcase_22 AC 245 ms
10,080 KB
testcase_23 AC 61 ms
7,520 KB
testcase_24 AC 97 ms
8,416 KB
testcase_25 AC 225 ms
7,776 KB
testcase_26 AC 251 ms
9,056 KB
testcase_27 AC 285 ms
9,952 KB
testcase_28 AC 165 ms
7,648 KB
testcase_29 AC 189 ms
8,672 KB
testcase_30 AC 57 ms
8,672 KB
testcase_31 AC 181 ms
6,676 KB
testcase_32 AC 99 ms
7,776 KB
testcase_33 AC 212 ms
7,392 KB
testcase_34 AC 76 ms
17,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef LOCAL
#include "./debug.cpp"
#else
#define debug(...)
#define print_line
#endif
using 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';
    }
}
0