This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include"friend.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 100005
int dp[N][2],col[N],cnt,cou,sum,ans;
bool f[3];
vector<int> g[N];
void dfs(int s,int f,int confidence[]){
for(auto x:g[s]){
if(x==f)continue;
dfs(x,s,confidence);
dp[s][1]+=dp[x][0];
dp[s][0]+=max(dp[x][0],dp[x][1]);
}
dp[s][1]+=confidence[s];
ans=max({ans,dp[s][0],dp[s][1]});
}
void bi(int s,int c){
if(col[s]!=-1)return ;
cnt++;
cou+=c;
col[s]=c;
for(auto x:g[s])bi(x,1-c);
}
int findSample(int n,int confidence[],int host[],int protocol[]){
int i,j,k;
if(n<=10){
bitset<15> vis[N];
for(i=0;i<=n;i++)vis[i]=0;
for(i=1;i<n;i++){
if(protocol[i])for(j=0;j<n;j++)if(vis[host[i]][j])vis[i][j]=vis[j][i]=true;
if(protocol[i]!=1)vis[i][host[i]]=vis[host[i]][i]=true;
}
for(i=0;i<(1<<n);i++){
sum=0;
for(j=0;j<n;j++){
if(i&(1<<j)){
for(k=0;k<n;k++)if(vis[j][k]&&(i&(1<<k)))break;
if(k!=n)break;
sum+=confidence[j];
}
}
if(j==n)ans=max(ans,sum);
}
}
else if(n<=1000){
for(i=1;i<n;i++)f[protocol[i]]=true;
if(!f[0]&&f[1]&&!f[2])for(i=0;i<n;i++)ans+=confidence[i];
else if(!f[0]&&!f[1]&&f[2])for(i=0;i<n;i++)ans=max(ans,confidence[i]);
else if(f[0]&&!f[1]&&!f[2]){
for(i=1;i<n;i++)g[i].push_back(host[i]),g[host[i]].push_back(i);
dfs(0,-1,confidence);
}
else{
for(i=1;i<n;i++){
if(protocol[i]==0)g[i].push_back(host[i]),g[host[i]].push_back(i);
else for(auto x:g[host[i]])g[i].push_back(x),g[x].push_back(i);
}
for(i=0;i<n;i++)col[i]=-1;
for(i=0;i<n;i++)if(col[i]==-1)cnt=cou=0,bi(i,0),ans+=max(cou,cnt-cou);
}
}
else{
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |