Submission #603873

#TimeUsernameProblemLanguageResultExecution timeMemory
6038738e7Friend (IOI14_friend)C++17
23 / 100
10 ms1264 KiB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r)cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 1005
#define pii pair<int, int>
#define ff first
#define ss second
#include "friend.h"

// Find out best sample
vector<int> adj[maxn];

int wei[maxn], col[maxn];
void dfs(int n, int c) {
	col[n] = c;	
	for (int v:adj[n]) {
		if (!col[v]) {
			dfs(v, 3 - c);
		} 
	}
}

int match[maxn]; 
bool vis[maxn];
bool alt(int n) {
	if (vis[n]) return 0;
	vis[n] = 1;
	for (int v:adj[n]) {
		if (match[v] == -1 || alt(match[v])) {
			match[n] = v;
			match[v] = n;
			return 1;
		}
	}
	return 0;
}
int findSample(int n,int C[],int h[],int type[]){
	for (int i = 0;i < n;i++) wei[i] = C[i];
	for (int i = 1;i < n;i++) {
		if (type[i] == 1 || type[i] == 2){
			for (int j:adj[h[i]]) {
				adj[i].push_back(j);
				adj[j].push_back(i);
			}
		} 
		if (type[i] == 0 || type[i] == 2) {
			adj[h[i]].push_back(i);
			adj[i].push_back(h[i]);
		}
	}
	for (int i = 0;i < n;i++) {
		if (!col[i]) dfs(i, 1);
	}
	int ans = 0;
	for (int i = 0;i < n;i++) match[i] = -1;
	for (int i = 0;i < n;i++) {
		if (col[i] == 1){
			for (int j = 0;j < n;j++) vis[j] = 0;
			if (alt(i)) ans++;
		}
	}
	ans = n - ans;
	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...