QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#763997#6438. CrystalflyhikaritocmWA 0ms13180kbC++141.4kb2024-11-19 23:16:222024-11-19 23:16:23

Judging History

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

  • [2024-11-19 23:16:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:13180kb
  • [2024-11-19 23:16:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[200005][2];
int a[200005], sum[200005];
bool 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[node]) 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++){
        int tmp;
        cin>>tmp;
        t[i]=(tmp==3);
    }
    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: 0
Wrong Answer
time: 0ms
memory: 13180kb

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
11101

result:

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