結果

問題 No.1637 Easy Tree Query
ユーザー CleyLCleyL
提出日時 2021-12-27 10:07:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 634 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 70,052 KB
実行使用メモリ 17,784 KB
最終ジャッジ日時 2023-10-25 08:35:52
合計ジャッジ時間 10,464 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,344 KB
testcase_01 AC 3 ms
6,348 KB
testcase_02 AC 261 ms
9,976 KB
testcase_03 AC 3 ms
6,344 KB
testcase_04 AC 65 ms
8,128 KB
testcase_05 AC 220 ms
7,548 KB
testcase_06 AC 143 ms
7,228 KB
testcase_07 AC 77 ms
6,416 KB
testcase_08 AC 52 ms
7,688 KB
testcase_09 AC 170 ms
9,092 KB
testcase_10 AC 98 ms
7,048 KB
testcase_11 AC 236 ms
9,416 KB
testcase_12 AC 232 ms
8,652 KB
testcase_13 AC 37 ms
7,092 KB
testcase_14 AC 106 ms
9,160 KB
testcase_15 AC 217 ms
9,560 KB
testcase_16 AC 163 ms
9,936 KB
testcase_17 AC 65 ms
7,088 KB
testcase_18 AC 203 ms
7,548 KB
testcase_19 AC 198 ms
7,848 KB
testcase_20 AC 245 ms
8,576 KB
testcase_21 AC 120 ms
8,184 KB
testcase_22 AC 253 ms
10,016 KB
testcase_23 AC 62 ms
7,256 KB
testcase_24 AC 99 ms
8,192 KB
testcase_25 AC 223 ms
7,440 KB
testcase_26 AC 247 ms
8,792 KB
testcase_27 AC 279 ms
9,844 KB
testcase_28 AC 160 ms
7,364 KB
testcase_29 AC 197 ms
8,452 KB
testcase_30 AC 60 ms
8,428 KB
testcase_31 AC 176 ms
6,356 KB
testcase_32 AC 98 ms
7,480 KB
testcase_33 AC 207 ms
7,068 KB
testcase_34 AC 76 ms
17,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
long long child[100001];
bool lck[100001];
vector<int> V[100001];
int dfs(int nw,int n){
  int ret = 0;
  for(int i = 0; V[nw].size() > i; i++){
    if(lck[V[nw][i]])continue;
    lck[V[nw][i]] = true;
    ret += dfs(V[nw][i],n);
  }
  return child[nw] = ret+1;
}
int main(){
  int n,q;cin>>n>>q;
  for(int i = 0; n-1 > i; i++){
    int s,t;cin>>s>>t;
    s--;t--;
    V[s].push_back(t);
    V[t].push_back(s);
  }
  lck[0] = true;
  dfs(0,n);
  long long ans = 0;
  for(int i = 0; q > i; i++){
    int p,x;cin>>p>>x;p--;
    ans += child[p]*x;
    cout << ans << endl;
  }
}
0