結果

問題 No.1637 Easy Tree Query
ユーザー 👑 jupirojupiro
提出日時 2021-08-06 22:19:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,295 bytes
コンパイル時間 2,717 ms
コンパイル使用メモリ 207,936 KB
実行使用メモリ 13,072 KB
最終ジャッジ日時 2023-10-17 05:11:30
合計ジャッジ時間 5,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 51 ms
9,640 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 20 ms
6,736 KB
testcase_05 AC 36 ms
5,740 KB
testcase_06 AC 24 ms
5,192 KB
testcase_07 AC 11 ms
4,348 KB
testcase_08 AC 16 ms
5,948 KB
testcase_09 AC 40 ms
8,056 KB
testcase_10 AC 18 ms
4,884 KB
testcase_11 AC 48 ms
8,584 KB
testcase_12 AC 42 ms
7,528 KB
testcase_13 AC 11 ms
4,956 KB
testcase_14 AC 31 ms
8,320 KB
testcase_15 AC 48 ms
8,848 KB
testcase_16 AC 42 ms
9,376 KB
testcase_17 AC 14 ms
4,952 KB
testcase_18 AC 34 ms
5,740 KB
testcase_19 AC 35 ms
6,208 KB
testcase_20 AC 45 ms
7,268 KB
testcase_21 AC 28 ms
6,736 KB
testcase_22 AC 53 ms
9,640 KB
testcase_23 AC 15 ms
5,244 KB
testcase_24 AC 24 ms
6,736 KB
testcase_25 AC 35 ms
5,568 KB
testcase_26 AC 47 ms
7,792 KB
testcase_27 AC 58 ms
9,376 KB
testcase_28 AC 28 ms
5,428 KB
testcase_29 AC 38 ms
7,084 KB
testcase_30 AC 21 ms
7,052 KB
testcase_31 AC 22 ms
4,348 KB
testcase_32 AC 21 ms
5,680 KB
testcase_33 AC 32 ms
4,916 KB
testcase_34 AC 31 ms
13,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
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; }
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

void solve()
{
  int n, kkt; cin >> n >> kkt;
  std::vector<std::vector<int>> g(n);
  for (int i = 0; i < n - 1; ++i)
  {
    int u, v; cin >> u >> v;
    u -= 1, v -= 1;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  std::vector<int> in(n), out(n);
  {
    int idx = 0;
    auto dfs = [&](auto &&self, int cur, int pre)->void
    {
      in[cur] = idx++;
      for (const auto &nxt : g[cur])
      {
        if(nxt == pre)
          continue;
        self(self, nxt, cur);
      }
      out[cur] = idx;
    };
    dfs(dfs, 0, -1);
  }
  ll res = 0;
  while(kkt--)
  {
    int p, x; cin >> p >> x;
    p -= 1;
    res += 1LL * x * (out[p] - in[p]);
    cout << res << "\n";
  }
  // cout << res << "\n";
}
int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int kkt = 1; 
  // cin >> kkt;
  while(kkt--)
    solve();
  return 0;
  
}
0