結果

問題 No.1637 Easy Tree Query
ユーザー umezoumezo
提出日時 2021-08-06 21:26:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 4,124 ms
コンパイル使用メモリ 203,816 KB
実行使用メモリ 16,140 KB
最終ジャッジ日時 2023-10-17 04:50:36
合計ジャッジ時間 8,449 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,096 KB
testcase_01 AC 2 ms
6,100 KB
testcase_02 AC 176 ms
9,896 KB
testcase_03 AC 3 ms
6,032 KB
testcase_04 AC 35 ms
8,160 KB
testcase_05 AC 158 ms
7,580 KB
testcase_06 AC 101 ms
7,196 KB
testcase_07 AC 58 ms
6,188 KB
testcase_08 AC 29 ms
7,716 KB
testcase_09 AC 107 ms
9,124 KB
testcase_10 AC 70 ms
6,972 KB
testcase_11 AC 154 ms
9,444 KB
testcase_12 AC 160 ms
8,680 KB
testcase_13 AC 24 ms
7,028 KB
testcase_14 AC 63 ms
9,192 KB
testcase_15 AC 142 ms
9,584 KB
testcase_16 AC 98 ms
9,884 KB
testcase_17 AC 45 ms
7,024 KB
testcase_18 AC 144 ms
7,576 KB
testcase_19 AC 139 ms
7,876 KB
testcase_20 AC 170 ms
8,608 KB
testcase_21 AC 80 ms
8,212 KB
testcase_22 AC 167 ms
9,948 KB
testcase_23 AC 42 ms
7,232 KB
testcase_24 AC 60 ms
8,224 KB
testcase_25 AC 158 ms
7,460 KB
testcase_26 AC 171 ms
8,824 KB
testcase_27 AC 188 ms
9,808 KB
testcase_28 AC 112 ms
7,364 KB
testcase_29 AC 129 ms
8,480 KB
testcase_30 AC 28 ms
8,456 KB
testcase_31 AC 133 ms
6,112 KB
testcase_32 AC 67 ms
7,508 KB
testcase_33 AC 151 ms
6,996 KB
testcase_34 AC 35 ms
16,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> G[100100];
ll A[100100];

void dfs(int v,int p){
  A[v]=1;
  for(auto nv:G[v]){
    if(nv==p) continue;
    dfs(nv,v);
    A[v]+=A[nv];
  }
} 
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  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,-1);
  
  ll ans=0;
  rep(i,q){
    ll p,x;
    cin>>p>>x;
    p--;
    ans+=A[p]*x;
    cout<<ans<<endl;
  }
  
    
  return 0;
}
0