結果

問題 No.1637 Easy Tree Query
ユーザー bonKotsubonKotsu
提出日時 2021-11-10 01:15:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 169,104 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-04-30 00:17:14
合計ジャッジ時間 9,777 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,760 KB
testcase_01 AC 3 ms
5,760 KB
testcase_02 AC 268 ms
9,088 KB
testcase_03 AC 4 ms
5,760 KB
testcase_04 AC 66 ms
7,680 KB
testcase_05 AC 224 ms
7,168 KB
testcase_06 AC 148 ms
6,784 KB
testcase_07 AC 80 ms
5,760 KB
testcase_08 AC 51 ms
7,168 KB
testcase_09 AC 176 ms
8,448 KB
testcase_10 AC 103 ms
6,656 KB
testcase_11 AC 245 ms
8,960 KB
testcase_12 AC 241 ms
8,192 KB
testcase_13 AC 39 ms
6,656 KB
testcase_14 AC 110 ms
8,448 KB
testcase_15 AC 231 ms
9,088 KB
testcase_16 AC 161 ms
9,344 KB
testcase_17 AC 68 ms
6,656 KB
testcase_18 AC 210 ms
7,040 KB
testcase_19 AC 209 ms
7,552 KB
testcase_20 AC 247 ms
8,064 KB
testcase_21 AC 121 ms
7,680 KB
testcase_22 AC 251 ms
9,216 KB
testcase_23 AC 65 ms
6,912 KB
testcase_24 AC 97 ms
7,680 KB
testcase_25 AC 224 ms
7,040 KB
testcase_26 AC 261 ms
8,192 KB
testcase_27 AC 293 ms
9,216 KB
testcase_28 AC 164 ms
7,040 KB
testcase_29 AC 196 ms
7,936 KB
testcase_30 AC 61 ms
7,936 KB
testcase_31 AC 180 ms
5,888 KB
testcase_32 AC 103 ms
7,040 KB
testcase_33 AC 222 ms
6,656 KB
testcase_34 AC 77 ms
15,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

vector<int> G[100005];
int c[100000];

void dfs(int v, int p = -1) {
  for (int nv : G[v]) {
    if (nv == p) continue; 
    dfs(nv, v);
    c[v]++;
    c[v]+=c[nv];
  }
}

int main() {
  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 ans = 0;
  rep(qi,q) {
    int p;
    ll x;
    cin >> p >> x;
    p--;
    ans += x*(c[p]+1);
    cout << ans << endl;
  }




}
0