Submission #748211

#TimeUsernameProblemLanguageResultExecution timeMemory
748211Username4132Friend (IOI14_friend)C++14
58 / 100
3 ms2900 KiB
#include "friend.h" #include<iostream> #include<vector> using namespace std; #define forn(i, n) for(int i=0; i<(int)n; ++i) #define forsn(i, s, n) for(int i=s; i<(int)n; ++i) #define PB push_back const int MAXN=100010; int n, dp[2][MAXN], conf[MAXN], mt[MAXN]; bool used[MAXN], even[MAXN]; vector<int> g[MAXN]; vector<int> base; void dfs(int v, int p){ dp[1][v]=conf[v]; for(int to:g[v]) if(to!=p) { dfs(to, v); dp[1][v]+=dp[0][to]; dp[0][v]+=dp[1][to]; } dp[1][v]=max(dp[0][v], dp[1][v]); } int solve0(int confidence[], int host[]){ forsn(i, 1, n) g[i].PB(host[i]), g[host[i]].PB(i); dfs(0, 0); return dp[1][0]; } int solve1(int confidence[], int host[]){ int sum=0; forn(i, n) sum+=confidence[i]; return sum; } int solve2(int confidence[], int host[]){ int mx=-1; forn(i, n) mx=max(mx, confidence[i]); return mx; } bool kuhn(int v){ if(used[v]) return false; used[v]=true; for(int to:g[v]) if(mt[to]==-1 || kuhn(mt[to])){ mt[to]=v; return true; } return false; } int solve3(int protocol[], int confidence[], int host[]){ forsn(i, 1, n){ if(protocol[i]==0){ even[i]=!even[host[i]]; g[host[i]].PB(i); g[i].PB(host[i]); } else{ even[i]=even[host[i]]; for(int to:g[host[i]]) g[i].PB(to), g[to].PB(i); } } forn(i, n) if(even[i]) base.PB(i); forn(i, n) mt[i]=-1; int ret=0; for(auto v:base){ for(auto i:base) used[i]=false; ret+=kuhn(v); } return n-ret; } int solveTask(int task, int confidence[], int host[]){ if(task==0) return solve0(confidence, host); else if(task==1) return solve1(confidence, host); else if(task==2) return solve2(confidence, host); } // Find out best sample int findSample(int N, int confidence[], int host[], int protocol[]){ n=N; forn(i, n) conf[i]=confidence[i]; bool eq=true; forsn(i, 1, n-1) eq&=protocol[i]==protocol[i+1]; if(eq) return solveTask(protocol[1], confidence, host); return solve3(protocol, confidence, host); return 0; }

Compilation message (stderr)

friend.cpp: In function 'int solveTask(int, int*, int*)':
friend.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
   80 | }
      | ^
#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...