結果

問題 No.1637 Easy Tree Query
ユーザー harurunharurun
提出日時 2021-06-19 01:00:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 79,584 KB
実行使用メモリ 14,948 KB
最終ジャッジ日時 2023-10-17 04:33:22
合計ジャッジ時間 8,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 269 ms
11,252 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 62 ms
7,292 KB
testcase_05 AC 223 ms
6,236 KB
testcase_06 AC 145 ms
5,480 KB
testcase_07 AC 78 ms
4,348 KB
testcase_08 AC 49 ms
6,500 KB
testcase_09 AC 169 ms
9,140 KB
testcase_10 AC 101 ms
5,100 KB
testcase_11 AC 237 ms
9,668 KB
testcase_12 AC 234 ms
8,348 KB
testcase_13 AC 37 ms
5,188 KB
testcase_14 AC 104 ms
9,140 KB
testcase_15 AC 218 ms
9,932 KB
testcase_16 AC 159 ms
10,724 KB
testcase_17 AC 65 ms
5,184 KB
testcase_18 AC 207 ms
6,236 KB
testcase_19 AC 201 ms
6,764 KB
testcase_20 AC 248 ms
8,084 KB
testcase_21 AC 121 ms
7,292 KB
testcase_22 AC 252 ms
11,048 KB
testcase_23 AC 61 ms
5,548 KB
testcase_24 AC 96 ms
7,292 KB
testcase_25 AC 229 ms
5,972 KB
testcase_26 AC 250 ms
8,612 KB
testcase_27 AC 283 ms
10,460 KB
testcase_28 AC 161 ms
5,768 KB
testcase_29 AC 196 ms
7,820 KB
testcase_30 AC 56 ms
7,820 KB
testcase_31 AC 181 ms
4,348 KB
testcase_32 AC 99 ms
6,016 KB
testcase_33 AC 213 ms
5,240 KB
testcase_34 AC 75 ms
14,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stdio.h>
#include <vector>
#include <deque>
using namespace std;
#define ll long long

vector<vector<ll>>d;
vector<ll>cnt;
vector<ll>B;

void f(int i){
  B.at(i)=1;
  for(ll j:d.at(i)){
    if(B.at(j)==0){
      f(j);
      cnt.at(i)+=cnt.at(j);
    }
  }
  return;
}

int main(){
  ll N,Q,a,b,ans=0,p,x;
  cin>>N>>Q;
  d.resize(N);
  cnt.resize(N);
  B.resize(N);
  for(int i=0;i<N-1;i++){
    cnt.at(i)=1;
    cin>>a>>b;
    d.at(a-1).push_back(b-1);
    d.at(b-1).push_back(a-1);
  }
  cnt.at(N-1)=1;
  f(0);
  for(int i=0;i<Q;i++){
    cin>>p>>x;
    ans+=cnt.at(p-1)*x;
    printf("%lld\n",ans);
  }
  return 0;
}
0