結果

問題 No.1637 Easy Tree Query
ユーザー chocorusk
提出日時 2021-08-06 21:23:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 2,906 ms
コンパイル使用メモリ 180,772 KB
最終ジャッジ日時 2025-01-23 14:27:19
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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