QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#723343#6438. CrystalflyIsacBieber#WA 1ms7404kbC++231.8kb2024-11-07 21:53:192024-11-07 21:53:20

Judging History

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

  • [2024-11-07 21:53:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7404kb
  • [2024-11-07 21:53:19]
  • 提交

answer

#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<":"<<x<<"\n"
using namespace std;
using ll = long long;
using pii = pair <int,int>;
const int N = 1e5 + 5, MOD = 1e9 + 7;
int n, t[N];
ll ans, a[N], f[N], df[N], sums[N];
vector <vector<int>> e(N);
void dfs(int u,int fa)
{
    f[u] = a[u];
    int m1 = 0, m2 = 0;
    ll sum = 0;
    for(auto son:e[u])
    {
        if(son!=fa)
        {
            dfs(son,u);
            if(a[son] >= a[m1]) {
                m2 = m1;
                m1 = son;
            } 
            else if(a[son] > a[m2]) {
                m2 = son;
            }
            sum += f[son] - a[son];
            df[u] += f[son];
            sums[u] += a[son];
        }
    }
    ll res = 0;
    for (auto son : e[u]) {
        if(son != fa) {
            if(t[son] == 3) {
                if(son == m1) {
                    res = std::max(res, f[son] + a[m2] + df[son] - sums[son]);
                }
                else {
                    res = std::max(res, f[son] + a[m1] + df[son] - sums[son]);
                }
                res = std::max(res, f[son] + sum - (f[son] - a[son]));
            }
            else {
                res = std::max(res, f[son] + sum - (f[son] - a[son]));
            }
        }
    }
    f[u] += res;
    ans = max(ans,f[u]);
}
void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        f[i] = 0;
        e[i].clear();
    }
    for(int i=1;i<=n;i++) cin>>t[i];
    for(int i=1,u,v;i<n;i++)
    {
        cin>>u>>v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    ans = 0;
    dfs(1,0);
    cout<<ans<<'\n';
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7404kb

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: 7364kb

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
39
25
115
31
52
42
60
19
47

result:

wrong answer 2nd numbers differ - expected: '24', found: '39'