Submission #278770

#TimeUsernameProblemLanguageResultExecution timeMemory
278770amiratouFriend (IOI14_friend)C++14
27 / 100
253 ms47096 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; set<int> adj[100005]; ll dp[100005][2],conf[100005],color[100005]; bool flag0,flag1,flag2,flag3; // Find out best sample void solve(int node,int p){ dp[node][1]=conf[node]; for(auto it:adj[node]){ if(it==p)continue; solve(it,node); dp[node][0]+=max(dp[it][0],dp[it][1]); dp[node][1]+=dp[it][0]; } } int findSample(int n,int confidence[],int host[],int protocol[]){ color[0]=-1,conf[0]=confidence[0]; if(conf[0]!=1)flag3=1; for (int i = 1; i < n; ++i) { color[i]=-1; conf[i]=confidence[i]; if(conf[i]!=1)flag3=1; if(protocol[i]==0){ flag0=1; adj[host[i]].insert(i); adj[i].insert(host[i]); } else if(protocol[i]==1){ flag1=1; for(auto it:adj[host[i]]) adj[i].insert(it),adj[it].insert(i); } else{ flag2=1; adj[host[i]].insert(i); adj[i].insert(host[i]); for(auto it:adj[host[i]]) adj[i].insert(it),adj[it].insert(i); } } ll ans=0; if(!n){ for (int mask = 0; mask < (1<<n); ++mask) { vector<int> vec; ll sum=0; bool f=1; for (int j = 0; j < n; ++j) { if((mask>>j) &1){ for(auto it:vec) if(adj[it].find(j)!=adj[it].end()){f=0;break;} if(!f)break; sum+=confidence[j],vec.push_back(j); } } if(f)ans=max(ans,sum); } } else if(!flag0 && !flag1){ for (int i = 0; i < n; ++i) ans=max(ans,(ll)confidence[i]); } else if(!flag0 && !flag2){ for (int i = 0; i < n; ++i) ans+=confidence[i]; } else if(!flag1 && !flag2){ solve(0,0); ans=max(dp[0][0],dp[0][1]); } else if(!flag2 && !flag3){ for (int i = 0; i < n; ++i) if(color[i]==-1){ //cerr<<i<<"\n"; int a=0,b=0; queue<int> q; q.push(i); color[i]=0; while(!q.empty()){ int f=q.front(); q.pop(); if(!color[f])a++; else b++; for(auto it:adj[f]){ if(color[it]!=-1)assert(color[it]!=color[f]); else color[it]=1-color[f],q.push(it); } } //cerr<<a<<","<<b<<"\n"; ans+=max(a,b); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...