結果

問題 No.1637 Easy Tree Query
ユーザー ppp-skyblueppp-skyblue
提出日時 2021-08-06 23:18:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 1,307 bytes
コンパイル時間 5,602 ms
コンパイル使用メモリ 230,728 KB
実行使用メモリ 17,360 KB
最終ジャッジ日時 2023-10-17 04:57:16
合計ジャッジ時間 12,996 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 260 ms
9,704 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 60 ms
6,536 KB
testcase_05 AC 222 ms
5,744 KB
testcase_06 AC 140 ms
5,216 KB
testcase_07 AC 75 ms
4,348 KB
testcase_08 AC 47 ms
6,008 KB
testcase_09 AC 161 ms
8,120 KB
testcase_10 AC 97 ms
4,724 KB
testcase_11 AC 225 ms
8,648 KB
testcase_12 AC 223 ms
7,592 KB
testcase_13 AC 36 ms
4,952 KB
testcase_14 AC 100 ms
8,384 KB
testcase_15 AC 212 ms
8,912 KB
testcase_16 AC 153 ms
9,440 KB
testcase_17 AC 63 ms
4,952 KB
testcase_18 AC 199 ms
5,744 KB
testcase_19 AC 194 ms
6,272 KB
testcase_20 AC 239 ms
7,328 KB
testcase_21 AC 117 ms
6,800 KB
testcase_22 AC 241 ms
9,704 KB
testcase_23 AC 60 ms
5,216 KB
testcase_24 AC 93 ms
6,800 KB
testcase_25 AC 217 ms
5,480 KB
testcase_26 AC 244 ms
7,592 KB
testcase_27 AC 266 ms
9,440 KB
testcase_28 AC 155 ms
5,480 KB
testcase_29 AC 184 ms
7,064 KB
testcase_30 AC 54 ms
7,064 KB
testcase_31 AC 174 ms
4,348 KB
testcase_32 AC 96 ms
5,480 KB
testcase_33 AC 206 ms
4,756 KB
testcase_34 AC 78 ms
17,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define frep(i,a,b) for (int i = (a); i <= (b); ++i)
#define all(x) (x).begin(),(x).end()
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define debug(x) cout << #x << ": " << x << endl;
typedef long long ll;
using P = pair<ll,ll>;
using P2 = pair<ll,P>;
using mint = modint1000000007;
#define INF 1001001001
#define LINF (1LL<<60)
#define F first
#define S second
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int n, q;
vector<vector<int>> to;
vector<ll> h;

void dfs(int v, int p = -1) {
  h[v] = 1;
  for (int u : to[v]) {
    if (u == p) continue;
    dfs(u, v);
    h[v] += h[u];
  }
  return;
}

int main() {
  cin >> n >> q;
  to.resize(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    to[a-1].push_back(b-1);
    to[b-1].push_back(a-1);
  }
  h.resize(n);
  dfs(0);
  ll ans = 0;
  rep(i, q) {
    ll p, x;
    cin >> p >> x;
    ans += h[p-1] * x;
    cout << ans << endl;
  }
}
0