結果
| 問題 | No.899 γatheree |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-08-25 00:51:15 |
| 言語 | C++14 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,232 bytes |
| 記録 | |
| コンパイル時間 | 395 ms |
| コンパイル使用メモリ | 80,384 KB |
| 実行使用メモリ | 6,924 KB |
| 最終ジャッジ日時 | 2026-08-25 00:51:27 |
| 合計ジャッジ時間 | 7,179 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 TLE * 1 -- * 2 |
ソースコード
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
const int N = 100010, M = 2 * N;
LL a[N];
vector<int> vec;
int n, q, h[N], e[M], ne[M], idx;
void Add(int x, int y) {
e[idx] = y, ne[idx] = h[x], h[x] = idx++;
}
void Solve(int u, int p, int step) {
vec.push_back(u);
if (step == 2) return;
for (int i = h[u]; i != -1; i = ne[i]) {
int v = e[i];
if (v == p) continue;
Solve(v, u, step + 1);
}
}
int main() {
// freopen("three.in", "r", stdin);
// freopen("three.out", "w", stdout);
scanf("%d", &n);
memset(h, -1, sizeof(h));
for (int i = 1, u, v; i <= n - 1; ++i) {
scanf("%d%d", &u, &v);
++u, ++v;
Add(u, v), Add(v, u);
}
for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
scanf("%d", &q);
while (q--) {
int x;
scanf("%d", &x);
++x;
vec.clear();
Solve(x, 0, 0);
for (auto i : vec) {
if (i == x) continue;
a[x] += a[i];
}
printf("%lld\n", a[x]);
for (auto i : vec) {
if (i == x) continue;
a[i] = 0;
}
}
return 0;
}