# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
57650 | FLDutchman | Friend (IOI14_friend) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define MMAX 16384
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;
const ll INF = 1000000000000000000LL;
const int NMAX = 1100;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);
vi match;
bitset<NMAX> vis;
vi adj[NMAX];
int aug(int n){
if(vis[n]) return 0;
vis[n] = 1;
for(int k : adj[n]) if(match[k] == -1 || aug(match[k])) {
match[k] = n;
match[n] = k;
return 1;
}
return 0;
}
int MCBM(){
int tot = 0;
FOR(i, 0, NMAX) if(match[i] == -1) vis.reset(), tot += aug(i);
return tot;
}
int findSample(int n, int confidence[], int host[], int protocol[]){
FOR(i, 1, n){
if(protocol[i] == 0 || protocol[i] == 2){
adj[host[i]].pb(i);
adj[i].pb(host[i]);
//cout << i << " " << host[i] << endl;
}
if(protocol[i] == 1 || protocol[i] == 2){
for(int k : adj[host[i]]){
//cout << i << " " << k << endl;
adj[k].pb(i);
adj[i].pb(k);
}
}
}
match.assign(NMAX, -1);
//cout<<endl;
int m = MCBM();
/*FOR(i, 0, n){
cout << i << " " << match[i] << endl;
}*/
return n - m;
}
/*
signed main(){
fast_io();
int N;
int conf[NMAX], host[NMAX], protocol[NMAX];
cin >> N;
FOR(i, 0, N) cin >> conf[i];
FOR(i, 1, N) cin >> host[i], cin >> protocol[i];
cout << findSample(N, conf, host, protocol);
}*/