Submission #404195

#TimeUsernameProblemLanguageResultExecution timeMemory
404195biggFriend (IOI14_friend)C++14
Compilation error
0 ms0 KiB
#include "friend.h"
#include<bits/stdc++.h>
using namespace std;
// Find out best sample
const int MAXN = 1e5 + 10;
vector<int> grafo[MAXN];
int dp[MAXN][5], v[MAXN], comp[MAXN], maxc[MAXN];
int mat[15][15];
void dfsc(int x, int p, int c){
	comp[x] = c;
	for(int v : grafo[x]){
		if(v == p) continue;
		dfsc(v, x, c);
	}
}

void dfs(int x, int p){
	dp[x][0] = 0, dp[x][1] = v[x];
	for(int v : grafo[x]){
		if(v == p) continue;
		dfs(v, x);
		dp[x][0] += max(dp[v][0], dp[v][1]);
		dp[x][1] += dp[v][0];
	}
}

int confidence[MAXN], host[MAXN], protocol[MAXN], n;

int solve1(){
	int ans = 0;
	for(int i = 1; i < n; i++){
			if(protocol[i] == 0){
				grafo[i].push_back(host[i]);
				grafo[host[i]].push_back(i);
				mat[i][host[i]] = mat[host[i]][i] = 1;
			}
			if(protocol[i] >= 1){
				for(int v : grafo[host[i]]){
					grafo[i].push_back(v);
					grafo[v].push_back(i);
					mat[i][v] = mat[v][i] = 1;
				}
				if(protocol[i] == 2){
					grafo[i].push_back(host[i]);
					grafo[host[i]].push_back(i);
					mat[i][host[i]] = mat[host[i]][i] = 1;
				}
			}
		}
		for(int i = 0; i < (1<<n); i++){
			int aq = 0;
			bool ok = 0;
			for(int v1 = 0; v1 < n; v1++){
				for(int v2 = v1 + 1; v2 < n; v2++){
					if((1<<v1) & i && (1<<v2) & i && mat[v1][v2]) ok = 1;
				}
			}
			if(ok) continue;
			for(int j = 0; j < n; j++){

				if((1<<j) & i) aq += confidence[j];
				
			}
			
			ans = max(ans, aq);
		}
		return ans;
}

int solve2(){
	int ans = 0;
	for(int i = 0; i < n; i++) ans += confidence[i];
	return ans;
}

int solve3(){
	for(int i = 0; i < n; i++) ans = max(ans, confidence[i]);
	return ans;
}

int solve4(){
	for(int i = 0; i < n; i++) v[i] = confidence[i];
	for(int i = 1; i < n; i++){
		grafo[host[i]].push_back(i);
		grafo[i].push_back(host[i]);
	}
	int c = 0;
	for(int i = 0; i < n; i++){
		if(!comp[i]){
			dfsc(i,i, ++c);
		}
	}
	for(int i = 0; i < n; i++){
		dfs(i, i);

		maxc[comp[i]] = max(maxc[comp[i]], dp[i][1]);
	}
	for(int i = 1; i <= c; i++) ans += maxc[i];
	return ans;
}


int marcb[MAXN], match[MAXN]
vector<int> qual[4];


bool dfsm(int x){
	for(int v : grafo[x]){
		if(marcb[v]) continue;
		marcb[v] = 1;
		if(match[v] == -1 || dfsm(match[v])){
			match[v] = x;
			match[x] = v;
			return true;
		}
	}
	return false;
}

int solve5(){
	qual[0].push_back(0);
	for(int i = 1; i < n; i++){
		if(protocol[i] == 0){
			grafo[host[i]].push_back(i);
			grafo[i].push_back(host[i]);
			comp[i] = 1-comp[host[i]];
			qual[comp[i]].push_back(i);
		}else{
			for(int v : grafo[host[i]]){
				grafo[i].push_back(v);
				grafo[v].push_back(i);
			}
			comp[i] = comp[host[i]];
			qual[comp[i]].push_back(i);
		}
	}
	for(int i = 0; i < n; i++) match[i] = -1;
	int ans = 0;
	bool flag=  1;
	while(flag){
		flag = 0;
		for(int i = 0; i < n; i++) marcb[i] = 0;
		for(int x : qual[0]){
			if(match[x] != -1) continue;
			if(dfsm(x)){
				flag = 1;
				ans++;
			}
		}
	}
	return n - ans;
}


int findSample(int N,int c[],int h[],int p[]){
	n = N;
	for(int i = 0; i < n; i++) confidence[i] = c[i];
	for(int i = 1; i < n; i++) host[i] = h[i], protocol[i] = p[i];
	if(n <= 10){
		return solve1();
	}
	int ok = 1;
	for(int i = 1; i < n; i++) if(protocol[i] != 1) ok = 0;
	if(ok){
		return solve2();	
	}
	ok = 1;
	for(int i = 1; i < n; i++) if(protocol[i] != 2) ok = 0;
	if(ok){
		return solve3();
		
	}
	ok = 1;
	for(int i = 1; i < n; i++) if(protocol[i] != 0) ok = 0;
	if(ok){
		return solve4();
	}
	return solve5();
	
}

Compilation message (stderr)

friend.cpp: In function 'int solve3()':
friend.cpp:77:29: error: 'ans' was not declared in this scope; did you mean 'abs'?
   77 |  for(int i = 0; i < n; i++) ans = max(ans, confidence[i]);
      |                             ^~~
      |                             abs
friend.cpp:78:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   78 |  return ans;
      |         ^~~
      |         abs
friend.cpp: In function 'int solve4()':
friend.cpp:98:30: error: 'ans' was not declared in this scope; did you mean 'abs'?
   98 |  for(int i = 1; i <= c; i++) ans += maxc[i];
      |                              ^~~
      |                              abs
friend.cpp:99:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
   99 |  return ans;
      |         ^~~
      |         abs
friend.cpp: At global scope:
friend.cpp:104:1: error: expected initializer before 'vector'
  104 | vector<int> qual[4];
      | ^~~~~~
friend.cpp: In function 'bool dfsm(int)':
friend.cpp:111:6: error: 'match' was not declared in this scope
  111 |   if(match[v] == -1 || dfsm(match[v])){
      |      ^~~~~
friend.cpp: In function 'int solve5()':
friend.cpp:121:2: error: 'qual' was not declared in this scope
  121 |  qual[0].push_back(0);
      |  ^~~~
friend.cpp:137:29: error: 'match' was not declared in this scope
  137 |  for(int i = 0; i < n; i++) match[i] = -1;
      |                             ^~~~~
friend.cpp:144:7: error: 'match' was not declared in this scope
  144 |    if(match[x] != -1) continue;
      |       ^~~~~