結果

問題 No.1637 Easy Tree Query
ユーザー NoviNovi
提出日時 2021-08-07 16:19:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 4,509 ms
コンパイル使用メモリ 232,336 KB
実行使用メモリ 14,376 KB
最終ジャッジ日時 2023-10-18 23:33:04
合計ジャッジ時間 13,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,336 KB
testcase_01 AC 4 ms
6,336 KB
testcase_02 AC 177 ms
10,416 KB
testcase_03 AC 4 ms
6,336 KB
testcase_04 AC 41 ms
8,304 KB
testcase_05 AC 163 ms
7,776 KB
testcase_06 AC 104 ms
7,512 KB
testcase_07 AC 60 ms
6,336 KB
testcase_08 AC 34 ms
8,040 KB
testcase_09 AC 117 ms
9,360 KB
testcase_10 AC 73 ms
7,248 KB
testcase_11 AC 165 ms
9,624 KB
testcase_12 AC 166 ms
8,832 KB
testcase_13 AC 26 ms
7,248 KB
testcase_14 AC 71 ms
9,360 KB
testcase_15 AC 155 ms
9,624 KB
testcase_16 AC 112 ms
10,152 KB
testcase_17 AC 47 ms
7,248 KB
testcase_18 AC 149 ms
7,776 KB
testcase_19 AC 144 ms
8,040 KB
testcase_20 AC 177 ms
8,832 KB
testcase_21 AC 84 ms
8,304 KB
testcase_22 AC 181 ms
10,152 KB
testcase_23 AC 44 ms
7,512 KB
testcase_24 AC 67 ms
8,304 KB
testcase_25 AC 166 ms
7,776 KB
testcase_26 AC 180 ms
9,096 KB
testcase_27 AC 206 ms
9,888 KB
testcase_28 AC 115 ms
7,512 KB
testcase_29 AC 137 ms
8,568 KB
testcase_30 AC 37 ms
8,568 KB
testcase_31 AC 137 ms
6,336 KB
testcase_32 AC 71 ms
7,776 KB
testcase_33 AC 154 ms
7,248 KB
testcase_34 AC 36 ms
14,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define int ll
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define ALL(a) (a).begin(), (a).end()
template <class t, class u> void chmax(t& a, u b) {
    if (a < b) a = b;
}
template <class t, class u> void chmin(t& a, u b) {
    if (b < a) a = b;
}
template <class t> using vc = vector<t>;
template <class t> using vvc = vc<vc<t>>;
using pi = pair<int, int>;
using vi = vc<int>;
using uint = unsigned;
using ull = unsigned long long;
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
ll mask(int i) { return (ll(1) << i) - 1; }
int lcm(int a, int b) { return a / __gcd(a, b) * b; }
vc<int> deg(100100, -1);
vvc<int> tree(100100);
int dfs(int u, int p = -1) {
    int cnt = 1;
    for (auto v : tree[u]) {
        if (v != p) {
            cnt += dfs(v, u);
        }
    }
    return deg[u] = cnt;
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
    int n, q;
    cin >> n >> q;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    int res = dfs(0);
    int tmp = 0;
    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        tmp += x * deg[p];
        cout << tmp << endl;
    }
}
0