結果

問題 No.1637 Easy Tree Query
ユーザー rogi52rogi52
提出日時 2022-10-01 06:05:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 202,980 KB
実行使用メモリ 18,240 KB
最終ジャッジ日時 2023-08-24 23:18:40
合計ジャッジ時間 10,522 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 58 ms
8,932 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 24 ms
6,208 KB
testcase_05 AC 40 ms
5,180 KB
testcase_06 AC 27 ms
4,536 KB
testcase_07 AC 12 ms
4,376 KB
testcase_08 AC 18 ms
5,436 KB
testcase_09 AC 43 ms
7,444 KB
testcase_10 AC 20 ms
4,376 KB
testcase_11 AC 55 ms
8,000 KB
testcase_12 AC 50 ms
6,936 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 36 ms
7,480 KB
testcase_15 AC 54 ms
8,232 KB
testcase_16 AC 51 ms
9,040 KB
testcase_17 AC 16 ms
4,376 KB
testcase_18 AC 39 ms
5,244 KB
testcase_19 AC 40 ms
5,660 KB
testcase_20 AC 53 ms
6,736 KB
testcase_21 AC 33 ms
6,168 KB
testcase_22 AC 65 ms
8,960 KB
testcase_23 AC 17 ms
4,560 KB
testcase_24 AC 29 ms
6,184 KB
testcase_25 AC 41 ms
5,100 KB
testcase_26 AC 55 ms
7,188 KB
testcase_27 AC 68 ms
8,516 KB
testcase_28 AC 32 ms
4,876 KB
testcase_29 AC 45 ms
6,596 KB
testcase_30 AC 26 ms
6,532 KB
testcase_31 AC 25 ms
4,376 KB
testcase_32 AC 23 ms
5,144 KB
testcase_33 AC 36 ms
4,376 KB
testcase_34 AC 40 ms
18,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int N,Q; cin >> N >> Q;
    vector<vector<int>> G(N);
    rep(i,N-1) {
        int u,v; cin >> u >> v; u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    
    vector<int> sz(N, 1);
    function<void(int,int)> dfs = [&](int v, int p) -> void {
        for(int to : G[v]) {
            if(to != p) {
                dfs(to, v);
                sz[v] += sz[to];
            }
        }
    }; dfs(0, -1);

    ll ans = 0;
    rep(_,Q) {
        int p,x; cin >> p >> x; p--;
        ans += 1LL * x * sz[p];
        cout << ans << "\n";
    }
}
0