結果

問題 No.1637 Easy Tree Query
ユーザー milanis48663220milanis48663220
提出日時 2021-08-06 21:25:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,285 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 119,296 KB
実行使用メモリ 16,196 KB
最終ジャッジ日時 2023-10-17 04:48:19
合計ジャッジ時間 7,365 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,156 KB
testcase_01 AC 3 ms
6,160 KB
testcase_02 AC 178 ms
9,952 KB
testcase_03 AC 3 ms
6,112 KB
testcase_04 AC 35 ms
8,268 KB
testcase_05 AC 156 ms
7,676 KB
testcase_06 AC 102 ms
7,280 KB
testcase_07 AC 59 ms
6,248 KB
testcase_08 AC 30 ms
7,820 KB
testcase_09 AC 107 ms
9,240 KB
testcase_10 AC 70 ms
7,052 KB
testcase_11 AC 155 ms
9,508 KB
testcase_12 AC 158 ms
8,804 KB
testcase_13 AC 24 ms
7,108 KB
testcase_14 AC 63 ms
9,296 KB
testcase_15 AC 142 ms
9,632 KB
testcase_16 AC 100 ms
9,940 KB
testcase_17 AC 46 ms
7,104 KB
testcase_18 AC 144 ms
7,676 KB
testcase_19 AC 139 ms
7,980 KB
testcase_20 AC 172 ms
8,728 KB
testcase_21 AC 81 ms
8,328 KB
testcase_22 AC 170 ms
10,004 KB
testcase_23 AC 42 ms
7,320 KB
testcase_24 AC 62 ms
8,336 KB
testcase_25 AC 158 ms
7,552 KB
testcase_26 AC 171 ms
8,948 KB
testcase_27 AC 188 ms
9,864 KB
testcase_28 AC 113 ms
7,456 KB
testcase_29 AC 129 ms
8,600 KB
testcase_30 AC 30 ms
8,576 KB
testcase_31 AC 136 ms
6,176 KB
testcase_32 AC 68 ms
7,604 KB
testcase_33 AC 154 ms
7,080 KB
testcase_34 AC 36 ms
16,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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; }

using namespace std;
typedef long long ll;

vector<int> g[100000];
ll ch[100000];
bool used[100000];

void dfs(int v){
    used[v] = true;
    ch[v] = 1;
    for(int to: g[v]){
        if(!used[to]) {
            dfs(to);
            ch[v] += ch[to];
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, q; 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);
    }
    ll ans = 0;
    dfs(0);
    while(q--){
        int p, x; cin >> p >> x;
        p--;
        ans += ch[p]*x;
        cout << ans << endl;
    }
}
0