結果

問題 No.1637 Easy Tree Query
ユーザー abc3abc3
提出日時 2021-08-06 22:48:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,347 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 203,800 KB
実行使用メモリ 16,900 KB
最終ジャッジ日時 2023-10-17 05:14:10
合計ジャッジ時間 8,353 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,856 KB
testcase_01 AC 3 ms
6,860 KB
testcase_02 AC 177 ms
10,656 KB
testcase_03 AC 3 ms
6,800 KB
testcase_04 AC 35 ms
8,920 KB
testcase_05 AC 155 ms
8,340 KB
testcase_06 AC 100 ms
7,956 KB
testcase_07 AC 59 ms
6,948 KB
testcase_08 AC 28 ms
8,476 KB
testcase_09 AC 104 ms
9,884 KB
testcase_10 AC 70 ms
7,732 KB
testcase_11 AC 149 ms
10,204 KB
testcase_12 AC 153 ms
9,440 KB
testcase_13 AC 23 ms
7,788 KB
testcase_14 AC 56 ms
9,952 KB
testcase_15 AC 133 ms
10,344 KB
testcase_16 AC 97 ms
10,644 KB
testcase_17 AC 44 ms
7,784 KB
testcase_18 AC 141 ms
8,336 KB
testcase_19 AC 138 ms
8,636 KB
testcase_20 AC 168 ms
9,368 KB
testcase_21 AC 78 ms
8,972 KB
testcase_22 AC 160 ms
10,708 KB
testcase_23 AC 41 ms
7,992 KB
testcase_24 AC 58 ms
8,984 KB
testcase_25 AC 158 ms
8,220 KB
testcase_26 AC 167 ms
9,584 KB
testcase_27 AC 178 ms
10,568 KB
testcase_28 AC 112 ms
8,124 KB
testcase_29 AC 126 ms
9,240 KB
testcase_30 AC 28 ms
9,216 KB
testcase_31 AC 136 ms
6,872 KB
testcase_32 AC 66 ms
8,268 KB
testcase_33 AC 152 ms
7,756 KB
testcase_34 AC 37 ms
16,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

   #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    typedef unsigned long long ull;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=998244353;
    
    vector<int>G[100005];
    int cnt;
    ll t[100005],have[100005];

    void dfs(int i,int pre=-1){
        t[i]=cnt++;
        for(int u:G[i]){
            if(u!=pre){
                dfs(u,i);
            }
        }
        have[i]=cnt-t[i];
    }
    void solve(){
        int n,q;
        cin>>n>>q;
        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 tot=0;
        rep(i,q){
            int p,x;
            cin>>p>>x;
            p--;
            tot+=have[p]*x;
            cout<<tot<<endl;
        }
    }

    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        solve();  

        return 0;
    }
0