結果

問題 No.1637 Easy Tree Query
ユーザー neckrawarmerneckrawarmer
提出日時 2021-10-17 20:00:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 4,310 ms
コンパイル使用メモリ 264,632 KB
実行使用メモリ 15,548 KB
最終ジャッジ日時 2023-10-17 22:32:24
合計ジャッジ時間 8,447 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 61 ms
10,268 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 28 ms
7,100 KB
testcase_05 AC 44 ms
6,308 KB
testcase_06 AC 30 ms
5,516 KB
testcase_07 AC 13 ms
4,348 KB
testcase_08 AC 22 ms
6,308 KB
testcase_09 AC 57 ms
8,420 KB
testcase_10 AC 22 ms
5,252 KB
testcase_11 AC 69 ms
8,948 KB
testcase_12 AC 57 ms
7,892 KB
testcase_13 AC 13 ms
5,252 KB
testcase_14 AC 45 ms
8,684 KB
testcase_15 AC 67 ms
9,212 KB
testcase_16 AC 64 ms
9,740 KB
testcase_17 AC 18 ms
5,252 KB
testcase_18 AC 41 ms
6,308 KB
testcase_19 AC 43 ms
6,572 KB
testcase_20 AC 57 ms
7,952 KB
testcase_21 AC 36 ms
7,100 KB
testcase_22 AC 76 ms
10,004 KB
testcase_23 AC 19 ms
5,780 KB
testcase_24 AC 33 ms
7,100 KB
testcase_25 AC 42 ms
6,044 KB
testcase_26 AC 60 ms
8,156 KB
testcase_27 AC 76 ms
9,740 KB
testcase_28 AC 33 ms
5,780 KB
testcase_29 AC 49 ms
7,628 KB
testcase_30 AC 29 ms
7,628 KB
testcase_31 AC 26 ms
4,348 KB
testcase_32 AC 26 ms
6,044 KB
testcase_33 AC 38 ms
5,252 KB
testcase_34 AC 35 ms
15,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
#endif
using ll = long long;
using ld = long double;
const ll INF = 1ll<<60;
const ld EPS = 1.0/1e9;
#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define del(x) sort(all(x)); x.erase(unique(all(x)),x.end());
vector<ll>x(101010,1);
void dfs(vector<vector<ll>>& G,int s,int p){
  fore(c,G[s]) if(c!=p){
    dfs(G,c,s);
    x[s]+=x[c];
  }
  return;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n,q; cin >> n >> q;
  vector<vector<ll>>G(n);
  rep(i,0,n-1){
    ll a,b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(G,0,-1);
  ll ans=0;
  rep(i,0,q){
    ll p,s; cin >> p >> s;
    p--; 
    ans+=x[p]*s;
    cout << ans << endl;
  }
}
0