結果

問題 No.899 γatheree
ユーザー niuezniuez
提出日時 2019-09-30 23:29:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,224 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 173,504 KB
実行使用メモリ 14,024 KB
最終ジャッジ日時 2024-04-14 08:22:56
合計ジャッジ時間 12,620 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,892 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 340 ms
10,112 KB
testcase_07 AC 351 ms
10,368 KB
testcase_08 AC 342 ms
10,112 KB
testcase_09 AC 350 ms
10,112 KB
testcase_10 AC 357 ms
10,156 KB
testcase_11 AC 348 ms
10,240 KB
testcase_12 AC 352 ms
10,240 KB
testcase_13 AC 346 ms
10,112 KB
testcase_14 AC 352 ms
10,112 KB
testcase_15 AC 354 ms
10,240 KB
testcase_16 AC 349 ms
10,112 KB
testcase_17 AC 350 ms
10,240 KB
testcase_18 AC 345 ms
10,084 KB
testcase_19 AC 352 ms
10,020 KB
testcase_20 AC 354 ms
10,112 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

int main() {
  i64 N;
  cin >> N;
  vector<vector<i64>> G(N);
  for(int i = 0;i < N - 1;i++) {
    i64 a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<i64> A(N);
  for(int i = 0;i < N;i++) {
    cin >> A[i];
  }
  i64 Q;
  cin >> Q;
  for(int i = 0;i < Q;i++) {
    i64 x;
    cin >> x;
    queue<pair<pair<i64, i64>, i64>> que;
    que.push({{x, -1}, 0});
    while(!que.empty()) {
      i64 v = que.front().first.first;
      i64 f = que.front().first.second;
      i64 d = que.front().second;
      que.pop();
      if(d == 2) continue;
      for(int t: G[v]) {
        if(t == f) continue;
        A[x] += A[t];
        A[t] = 0;
        que.push({{t, v}, d + 1});
      }
    }
    cout << A[x] << endl;
  }
}
0