結果

問題 No.1637 Easy Tree Query
ユーザー 👑 NachiaNachia
提出日時 2021-08-06 21:36:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 88,220 KB
実行使用メモリ 12,460 KB
最終ジャッジ日時 2023-10-17 05:02:53
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 54 ms
9,028 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 21 ms
6,388 KB
testcase_05 AC 38 ms
5,500 KB
testcase_06 AC 26 ms
5,072 KB
testcase_07 AC 11 ms
4,348 KB
testcase_08 AC 16 ms
5,692 KB
testcase_09 AC 39 ms
7,708 KB
testcase_10 AC 19 ms
4,744 KB
testcase_11 AC 50 ms
8,236 KB
testcase_12 AC 44 ms
7,180 KB
testcase_13 AC 11 ms
4,820 KB
testcase_14 AC 31 ms
7,972 KB
testcase_15 AC 48 ms
8,500 KB
testcase_16 AC 41 ms
9,028 KB
testcase_17 AC 14 ms
4,816 KB
testcase_18 AC 35 ms
5,500 KB
testcase_19 AC 36 ms
5,916 KB
testcase_20 AC 46 ms
6,928 KB
testcase_21 AC 27 ms
6,388 KB
testcase_22 AC 57 ms
9,028 KB
testcase_23 AC 15 ms
5,132 KB
testcase_24 AC 24 ms
6,396 KB
testcase_25 AC 36 ms
5,336 KB
testcase_26 AC 46 ms
7,232 KB
testcase_27 AC 55 ms
8,764 KB
testcase_28 AC 27 ms
5,328 KB
testcase_29 AC 38 ms
6,916 KB
testcase_30 AC 22 ms
6,724 KB
testcase_31 AC 23 ms
4,348 KB
testcase_32 AC 21 ms
5,404 KB
testcase_33 AC 33 ms
4,776 KB
testcase_34 AC 30 ms
12,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <atcoder/maxflow>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
#define rep(i,n) for(int i=0; i<(n); i++)


int N, Q;
vector<vector<int>> E;
vector<int> Z;
vector<i64> A;

int main(){
  cin >> N >> Q;
  E.resize(N);
  rep(i,N-1){
    int u,v; cin >> u >> v; u--; v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  Z.assign(N,1);
  auto dfs = [&](int p,int pre,auto dfs)->void{
    for(int e : E[p]) if(pre != e){
      dfs(e,p,dfs);
      Z[p] += Z[e];
    }
  };
  dfs(0,-1,dfs);

  i64 ans = 0;
  rep(i,Q){
    int p; i64 x; cin >> p >> x; p--;
    ans += x * Z[p];
    cout << ans << "\n";
  }
  return 0;
}




struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;




0