Submission #232087

#TimeUsernameProblemLanguageResultExecution timeMemory
232087anonymousFriend (IOI14_friend)C++14
46 / 100
41 ms4480 KiB
#include "friend.h" #include <vector> #include <iostream> #define MAXN 1005 using namespace std; // Find out best sample vector <int> adj[MAXN]; int wt[MAXN], dp[MAXN][2]; bool done[MAXN][2]; int slv(int u, int prev, bool b) { if (done[u][b]) {return(dp[u][b]);} done[u][b]=true; for (int v: adj[u]) { if (v == prev) {continue;} dp[u][b] += slv(v, u, 1); } if (b == 1) { int v2 = wt[u]; for (int v: adj[u]) { if (v == prev) {continue;} v2 += slv(v, u, 0); } dp[u][b] = max(dp[u][b], v2); } return(dp[u][b]); } //Max matching int Match[MAXN], vis[MAXN], Num; bool dfs(int u, int t) { vis[u] = t; for (int v: adj[u]) { if (vis[v] == t) {continue;} vis[v] = t; if (Match[v] == -1) { Match[u] = v, Match[v] = u; return(true); } else if (vis[Match[v]] != t && dfs(Match[v], t)) { Match[u] = v, Match[v] = u; return(true); } } return(false); } int findSample(int n,int C[],int H[],int P[]){ //confidence, host, protocol bool SB1=n <= 12, SB2=true, SB3=true, SB4=true, SB5=true; for (int i=1; i<n; i++) { if (P[i] != 1) {SB2=false;} //myfriends if (P[i] != 2) {SB3 = false;} //ourfriends if (P[i] != 0) {SB4 = false;} //Ifriends if (P[i] == 2) {SB5 = false;} } for (int i=1; i<n; i++) { if (P[i] == 0) { //I am friend adj[i].push_back(H[i]); adj[H[i]].push_back(i); //printf("%d %d\n",i,H[i]); } else if (P[i] == 1) { //My friends for (int v: adj[H[i]]) { adj[i].push_back(v); adj[v].push_back(i); //printf("%d %d\n",v,i); } } else { //everything //printf("%d %d\n",i,H[i]); for (int v: adj[H[i]]) { adj[i].push_back(v); adj[v].push_back(i); //printf("%d %d\n",v,i); } adj[i].push_back(H[i]); adj[H[i]].push_back(i); } } for (int i=0; i<n; i++) { wt[i] = C[i]; } if (SB1) { int ans = 0; for (int i=0; i<(1<<n); i++) { bool ok = true; for (int a=0; a<n; a++) { for (int b: adj[a]) { if ((i&(1<<a)) && (i&(1<<b))) { ok = false; } } } if (ok) { int res = 0; for (int j=0; j<n; j++) { if (i&(1<<j)) {res += C[j];} } ans = max(ans, res); } } return(ans); } else if (SB3) { //no edges with myfriends int mx = 0; for (int i=0; i<n; i++) { mx = max(mx, C[i]); } return(mx); } else if (SB2) { //everything connected int Sum = 0; for (int i=0; i<n; i++) { Sum += C[i]; } return(Sum); } else if (SB4) { return(slv(0,-1,1)); } else if (SB5) { for (int i=0; i<n; i++) { Match[i] = -1; } for (int i=0; i<n; i++) { Num += (int) dfs(i, i+1); } return(n - Num); } }

Compilation message (stderr)

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