結果

問題 No.899 γatheree
ユーザー ecto0310ecto0310
提出日時 2019-10-04 21:44:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 852 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 172,120 KB
実行使用メモリ 17,848 KB
最終ジャッジ日時 2024-04-14 10:26:38
合計ジャッジ時間 6,764 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,888 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  vector<i64> edge[n];
  for (i64 i = 0; i < n - 1; i++)
  {
    i64 w, v;
    cin >> w >> v;
    edge[w].push_back(v);
    edge[v].push_back(w);
  }
  vector<i64> cnt(n);
  for (i64 i = 0; i < n; i++)
    cin >> cnt[i];
  i64 q;
  cin >> q;
  for (i64 _ = 0; _ < q; _++)
  {
    i64 x;
    cin >> x;
    i64 ans = 0;
    queue<i64> que;
    vector<i64> far(n, 1e9);
    que.push(x);
    far[x] = 0;
    while (que.size())
    {
      i64 p = que.front();
      que.pop();
      ans += cnt[p];
      cnt[p] = 0;
      for (i64 i : edge[p])
        if (far[p] < 2 && far[p] + 1 < far[i])
        {
          far[i] = far[p] + 1;
          que.push(i);
        }
    }
    cnt[x] = ans;
    cout << ans << endl;
  }
  return 0;
}
0