結果

問題 No.1637 Easy Tree Query
ユーザー KKT89KKT89
提出日時 2021-08-06 21:23:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 3,282 ms
コンパイル使用メモリ 217,596 KB
実行使用メモリ 13,032 KB
最終ジャッジ日時 2023-10-17 04:39:59
合計ジャッジ時間 8,310 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 64 ms
9,044 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 30 ms
6,436 KB
testcase_05 AC 47 ms
5,768 KB
testcase_06 AC 34 ms
4,796 KB
testcase_07 AC 14 ms
4,348 KB
testcase_08 AC 22 ms
5,820 KB
testcase_09 AC 58 ms
7,772 KB
testcase_10 AC 23 ms
4,560 KB
testcase_11 AC 72 ms
8,228 KB
testcase_12 AC 58 ms
7,172 KB
testcase_13 AC 13 ms
4,608 KB
testcase_14 AC 41 ms
7,964 KB
testcase_15 AC 66 ms
8,492 KB
testcase_16 AC 61 ms
9,020 KB
testcase_17 AC 18 ms
4,604 KB
testcase_18 AC 44 ms
5,768 KB
testcase_19 AC 46 ms
6,044 KB
testcase_20 AC 59 ms
7,056 KB
testcase_21 AC 36 ms
6,512 KB
testcase_22 AC 75 ms
9,056 KB
testcase_23 AC 19 ms
5,060 KB
testcase_24 AC 33 ms
6,524 KB
testcase_25 AC 46 ms
5,464 KB
testcase_26 AC 61 ms
7,496 KB
testcase_27 AC 75 ms
8,816 KB
testcase_28 AC 35 ms
5,060 KB
testcase_29 AC 47 ms
6,908 KB
testcase_30 AC 26 ms
6,852 KB
testcase_31 AC 28 ms
4,348 KB
testcase_32 AC 26 ms
5,532 KB
testcase_33 AC 40 ms
4,580 KB
testcase_34 AC 36 ms
13,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    vector<vector<int>> g(n);
    for(int i=0;i<n-1;i++){
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }    
    vector<int> d(n);
    auto dfs=[&](auto dfs,int s,int p)->void{
        d[s]=1;
        for(int t:g[s]){
            if(t==p)continue;
            dfs(dfs,t,s);
            d[s]+=d[t];
        }
    };
    dfs(dfs,0,-1);
    ll res=0;
    for(int i=0;i<q;i++){
        ll p,x; cin >> p >> x;
        p--;
        res+=(ll)d[p]*x;
        printf("%lld\n",res);
    }
}
0