結果
| 問題 |
No.899 γatheree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-30 23:29:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,224 bytes |
| コンパイル時間 | 1,728 ms |
| コンパイル使用メモリ | 177,420 KB |
| 実行使用メモリ | 17,908 KB |
| 最終ジャッジ日時 | 2024-10-03 05:29:24 |
| 合計ジャッジ時間 | 11,235 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 TLE * 1 -- * 2 |
ソースコード
#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;
}
}