QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639454#6438. Crystalflywht11WA 0ms11788kbC++141.9kb2024-10-13 19:41:082024-10-13 19:41:09

Judging History

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

  • [2024-10-13 19:41:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11788kb
  • [2024-10-13 19:41:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) (x & (-x))
#define debug(x) cerr << #x << ": " << x << endl;
const int N = 2e5 + 10;
int n;
int a[N], t[N];
vector<int> g[N];
int dp[N][2];
int sum[N];
void dfs(int u, int fa)
{
    int mx = 0;
    int mx1 = 0, mx2 = 0;
    for (auto v : g[u])
    {
        if (v == fa)
            continue;
        dfs(v, u);
        sum[u] += dp[v][0];
        if (sum[mx1] + a[mx1] - dp[mx1][0] < sum[v] + a[v] - dp[v][0])
        {
            mx2 = mx1;
            mx1 = v;
        }
        else if (sum[mx1] + a[mx1] - dp[mx1][0] < sum[v] + a[v] - dp[v][0])
            mx2 = v;
        mx = max(mx, a[v]);
    }
    dp[u][0] = sum[u] + mx;
    for (auto v : g[u])
    {
        if (v == fa)
            continue;
        if (t[v] == 3)
        {
            if (g[u].size() == 2)
                continue;
            if (mx1 == v)
            {
                if (mx2)
                    dp[u][0] = max(dp[u][0], sum[u] - dp[mx2][0] + sum[mx2] + a[mx2] + a[v]);
            }
            else
                dp[u][0] = max(dp[u][0], sum[u] - dp[mx1][0] + sum[mx1] + a[mx1] + a[v]);
        }
    }
    return;
}
void solve()
{
    dp[0][0] = 1e18;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> t[i];
    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, 0);
    cout << dp[1][0] + a[1] << "\n";
    for (int i = 1; i <= n; i++)
    {
        g[i].clear();
        dp[i][1] = dp[i][0] = sum[i] = 0;
    }
    return;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11788kb

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
10101

result:

wrong answer 2nd numbers differ - expected: '10111', found: '10101'