結果

問題 No.1637 Easy Tree Query
ユーザー yakkiyakki
提出日時 2021-08-06 21:28:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 3,763 ms
コンパイル使用メモリ 123,528 KB
実行使用メモリ 15,476 KB
最終ジャッジ日時 2023-10-17 04:54:47
合計ジャッジ時間 7,851 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 228 ms
9,140 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 50 ms
6,500 KB
testcase_05 AC 185 ms
5,444 KB
testcase_06 AC 123 ms
4,916 KB
testcase_07 AC 68 ms
4,348 KB
testcase_08 AC 43 ms
5,708 KB
testcase_09 AC 135 ms
7,820 KB
testcase_10 AC 85 ms
4,652 KB
testcase_11 AC 193 ms
8,348 KB
testcase_12 AC 197 ms
7,292 KB
testcase_13 AC 30 ms
4,652 KB
testcase_14 AC 85 ms
7,820 KB
testcase_15 AC 179 ms
8,612 KB
testcase_16 AC 125 ms
9,140 KB
testcase_17 AC 54 ms
4,652 KB
testcase_18 AC 172 ms
5,444 KB
testcase_19 AC 168 ms
5,972 KB
testcase_20 AC 215 ms
7,028 KB
testcase_21 AC 98 ms
6,500 KB
testcase_22 AC 204 ms
9,140 KB
testcase_23 AC 52 ms
4,916 KB
testcase_24 AC 78 ms
6,500 KB
testcase_25 AC 193 ms
5,444 KB
testcase_26 AC 214 ms
7,292 KB
testcase_27 AC 237 ms
8,876 KB
testcase_28 AC 137 ms
5,180 KB
testcase_29 AC 159 ms
6,764 KB
testcase_30 AC 48 ms
6,764 KB
testcase_31 AC 154 ms
4,348 KB
testcase_32 AC 83 ms
5,444 KB
testcase_33 AC 180 ms
4,652 KB
testcase_34 AC 69 ms
15,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<ctime>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint1000000007;

int dh[] = {-1,0,1,0};
int dw[] = {0,1,0,-1};

int sz[100010];
vector<vector<int>> G;
int n,q;

void dfs(int u, int p = -1){
    sz[u] = 1;
    for(auto v : G[u]){
        if(v == p) continue;
        dfs(v,u);
        sz[u] += sz[v];
    }
}

int main(){
    cin >> n >> q;
    G.resize(n);
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0);
    ll ans = 0;
    while(q--){
        int p,x; cin >> p >> x;
        p--;
        ans += 1LL*sz[p]*x;
        cout << ans << endl;
    }
}

0