結果

問題 No.1637 Easy Tree Query
ユーザー chocoruskchocorusk
提出日時 2021-08-06 21:23:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 3,745 ms
コンパイル使用メモリ 188,788 KB
実行使用メモリ 15,728 KB
最終ジャッジ日時 2023-10-17 04:36:51
合計ジャッジ時間 11,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,972 KB
testcase_01 AC 2 ms
5,976 KB
testcase_02 AC 260 ms
9,484 KB
testcase_03 AC 2 ms
5,932 KB
testcase_04 AC 58 ms
7,832 KB
testcase_05 AC 218 ms
7,308 KB
testcase_06 AC 142 ms
6,960 KB
testcase_07 AC 77 ms
6,052 KB
testcase_08 AC 47 ms
7,432 KB
testcase_09 AC 164 ms
8,700 KB
testcase_10 AC 98 ms
6,760 KB
testcase_11 AC 221 ms
8,992 KB
testcase_12 AC 225 ms
8,300 KB
testcase_13 AC 36 ms
6,808 KB
testcase_14 AC 99 ms
8,764 KB
testcase_15 AC 207 ms
9,124 KB
testcase_16 AC 150 ms
9,464 KB
testcase_17 AC 63 ms
6,804 KB
testcase_18 AC 203 ms
7,308 KB
testcase_19 AC 193 ms
7,576 KB
testcase_20 AC 242 ms
8,236 KB
testcase_21 AC 118 ms
7,880 KB
testcase_22 AC 239 ms
9,536 KB
testcase_23 AC 61 ms
6,992 KB
testcase_24 AC 92 ms
7,888 KB
testcase_25 AC 221 ms
7,200 KB
testcase_26 AC 241 ms
8,432 KB
testcase_27 AC 268 ms
9,376 KB
testcase_28 AC 159 ms
7,112 KB
testcase_29 AC 186 ms
8,124 KB
testcase_30 AC 53 ms
8,100 KB
testcase_31 AC 177 ms
5,984 KB
testcase_32 AC 96 ms
7,244 KB
testcase_33 AC 208 ms
6,780 KB
testcase_34 AC 75 ms
15,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
int n, q;
vector<int> g[100010];
int c[100010];
void dfs(int x, int p){
    c[x]=1;
    for(auto y:g[x]){
        if(y==p) continue;
        dfs(y, x);
        c[x]+=c[y];
    }
}
int main()
{
	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);
    }
    dfs(0, -1);
    ll ans=0;
    for(int i=0; i<q; i++){
        int p; ll x; cin>>p>>x; p--;
        ans+=c[p]*x;
        cout<<ans<<endl;
    }
    return 0;
}
0