QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215996 | #6438. Crystalfly | veg# | WA | 0ms | 6764kb | C++14 | 1.2kb | 2023-10-15 15:01:02 | 2023-10-15 15:01:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], t[100005];
long long sum[100005], dp[100005];
vector<int> G[100005];
void dfs(int u, int fa) {
dp[u] = sum[u] = 0;
int mx1 = -1e9, mx2 = -1e9, id1 = 0, id2 = 0;
for (int v : G[u]) {
if (v == fa) continue;
dfs(v, u);
sum[u] += dp[v];
dp[u] = max(dp[u], 1ll * a[v]);
if (t[v] >= 3) {
if (a[v] >= mx1) {
id2 = id1, mx2 = mx1;
mx1 = a[v], id1 = v;
} else if (a[v] >= mx2)
id2 = v, mx2 = a[v];
}
}
dp[u] += sum[u];
for (int w : G[u]) {
if (w == id1)
dp[u] = max(dp[u], sum[u] - dp[w] + mx2 + sum[w] + a[w]);
else
dp[u] = max(dp[u], sum[u] - dp[w] + mx1 + sum[w] + a[w]);
}
}
int main() {
int T;
cin >> T;
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i)
scanf("%d", &t[i]);
for (int i = 1; i <= n; ++i) G[i].clear();
for (int i = 1; i < n; ++i) {
int u, v;
scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 0);
// for (int i = 1; i <= n; ++i)
// printf("dp[%d]:%lld\n", i, dp[i]);
printf("%lld\n", dp[1] + a[1]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 6764kb
input:
2 5 1 10 100 1000 10000 1 2 1 1 1 1 2 1 3 2 4 2 5 5 1 10 100 1000 10000 1 3 1 1 1 1 2 1 3 2 4 2 5
output:
10101 10111
result:
ok 2 number(s): "10101 10111"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 6580kb
input:
10 6 8 1 1 5 8 9 2 1 2 2 2 2 1 2 2 3 2 4 1 5 2 6 6 6 4 4 1 3 6 2 1 3 3 3 3 1 2 1 3 3 4 4 5 5 6 6 10 5 1 8 5 1 1 3 1 2 2 2 1 2 2 3 2 4 2 5 3 6 10 6 8 8 9 6 9 5 6 6 4 2 1 3 3 2 2 2 2 3 1 1 2 1 3 3 4 4 5 5 6 4 7 2 8 7 9 9 10 7 10 9 1 5 7 5 4 1 1 1 2 1 3 2 1 2 1 3 3 4 3 5 5 6 1 7 5 7 1 1 4 2 3 1 3 2 2 1...
output:
25 31 24 72 31 14 18 28 19 19
result:
wrong answer 2nd numbers differ - expected: '24', found: '31'