QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424118#6438. CrystalflyPorNPtreeWA 2ms8156kbC++141.1kb2024-05-28 22:02:382024-05-28 22:02:41

Judging History

你现在查看的是最新测评结果

  • [2024-05-28 22:02:41]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8156kb
  • [2024-05-28 22:02:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

int a[N], t[N];
long long f[N][2];
vector<int> G[N];

void dfs(int x, int fa = -1) {
    f[x][1] = a[x];
    long long mx = 0, mx1 = -1e18, mx2 = -1e18;
    for (auto v : G[x]) if (v != fa) {
        dfs(v, x), f[x][1] += f[v][0] - a[v];
        mx = max(mx, (long long)a[v]);
        if (t[v] == 3) mx = max(mx, mx1 + a[v]);
        mx1 = max(mx1, f[v][1] - f[v][0] + a[v]);
        mx = max(mx, mx2 + f[v][1] - f[v][0] + a[v]);
        if (t[v] == 3) mx2 = max(mx, (long long)a[v]);
    }
    f[x][0] = f[x][1] + mx;
}

signed main() {
    int T; scanf("%d", &T);
    while (T--) {
        int n; 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]);
            G[i].clear();
        }
        for (int i = 1, x, y; i < n; ++i) {
            scanf("%d%d", &x, &y);
            G[x].push_back(y), G[y].push_back(x);
        }
        dfs(1);
        printf("%lld\n", f[1][0]);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8156kb

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: 1ms
memory: 7072kb

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
24
24
56
31
14
16
32
19
19

result:

wrong answer 8th numbers differ - expected: '28', found: '32'