QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764004#6438. CrystalflyhikaritocmWA 2ms14240kbC++141.3kb2024-11-19 23:18:312024-11-19 23:18:31

Judging History

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

  • [2024-11-19 23:18:31]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:14240kb
  • [2024-11-19 23:18:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[200005][2];
int a[200005], sum[200005];
int t[200005];
vector<int> adj[200005];
int n;
void dfs(int node, int pre){
    multiset<int> s;
    s.insert(0);
    for(int i: adj[node]){
        if(i!=pre){
            dfs(i,node);
        }
    }
    for(int i: adj[node]){
        if(i==pre) continue;
        sum[node]+=dp[i][0];
        s.insert(sum[i]+a[i]-dp[i][0]);
    }
    int res=sum[node];
    for(int i: adj[node]){
        if(i==pre) continue;
        int val=sum[i]+a[i]-dp[i][0];
        s.erase(s.find(val));
        dp[node][0]=max(dp[node][0],res+a[i]);
        if(t[i]==3) dp[node][0]=max(dp[node][0],*s.rbegin()+res+a[i]);
    }
    dp[node][1]=dp[node][0]+a[node];
}
void solve(){
    cin>>n;
    for(int i=0; i<=n; i++){
        adj[i].clear();
        a[i]=0;
        sum[i]=0;
        dp[i][0]=dp[i][1]=0;
        t[i]=0;
    }
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    for(int i=1; i<=n; i++){
        cin>>t[i];
    }
    for(int i=0; i<n-1; i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,0);
    cout<<dp[1][1]<<endl;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin>>t;
	while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
20
24
54
31
14
16
28
19
18

result:

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