結果

問題 No.1637 Easy Tree Query
ユーザー HaaHaa
提出日時 2021-08-06 21:26:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 3,874 ms
コンパイル使用メモリ 171,280 KB
実行使用メモリ 13,608 KB
最終ジャッジ日時 2023-10-17 04:50:05
合計ジャッジ時間 9,293 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,504 KB
testcase_01 AC 4 ms
6,504 KB
testcase_02 AC 259 ms
10,704 KB
testcase_03 AC 4 ms
6,504 KB
testcase_04 AC 61 ms
8,592 KB
testcase_05 AC 218 ms
8,064 KB
testcase_06 AC 143 ms
7,800 KB
testcase_07 AC 78 ms
6,504 KB
testcase_08 AC 49 ms
8,328 KB
testcase_09 AC 164 ms
9,648 KB
testcase_10 AC 99 ms
7,536 KB
testcase_11 AC 224 ms
9,912 KB
testcase_12 AC 228 ms
9,120 KB
testcase_13 AC 38 ms
7,536 KB
testcase_14 AC 104 ms
9,648 KB
testcase_15 AC 208 ms
9,912 KB
testcase_16 AC 156 ms
10,440 KB
testcase_17 AC 65 ms
7,536 KB
testcase_18 AC 198 ms
8,064 KB
testcase_19 AC 194 ms
8,328 KB
testcase_20 AC 242 ms
9,120 KB
testcase_21 AC 120 ms
8,592 KB
testcase_22 AC 237 ms
10,440 KB
testcase_23 AC 63 ms
7,800 KB
testcase_24 AC 95 ms
8,856 KB
testcase_25 AC 216 ms
8,064 KB
testcase_26 AC 243 ms
9,384 KB
testcase_27 AC 268 ms
10,176 KB
testcase_28 AC 157 ms
7,800 KB
testcase_29 AC 192 ms
8,856 KB
testcase_30 AC 56 ms
8,856 KB
testcase_31 AC 170 ms
6,504 KB
testcase_32 AC 98 ms
8,064 KB
testcase_33 AC 208 ms
7,536 KB
testcase_34 AC 75 ms
13,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

VI g[110000];
VI c(110000);

int dfs(int v, int p){
    int ret=1;
    for(auto to:g[v]){
        if(to!=p)
            ret+=dfs(to,v);
    }
    c[v]=ret;
    return ret;
}

int main(){
    int n, q; cin >> n >> q;
    int a, b;
    REP(i,n-1){
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,-1);
    int p, x;
    ll ans=0;
    REP(i,q){
        cin >> p >> x;
        p--;
        ans+=c[p]*x;
        cout << ans << endl;
    }
    return 0;
}
0