# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
742219 | MODDI | 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 "friend.h"
#include "grader.cpp"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define vi vector<int>
using namespace std;
bool find(int j, vector<vi>& g, vi& btoa, vi& vis) {
if (btoa[j] == -1) return 1;
vis[j] = 1; int di = btoa[j];
for (int e : g[di])
if (!vis[e] && find(e, g, btoa, vis)) {
btoa[e] = di;
return 1;
}
return 0;
}
int dfsMatching(vector<vi>& g, vi& btoa) {
vi vis;
for(int i = 0; i < g.size(); i++) {
vis.assign(btoa.size(), 0);
for (int j : g[i])
if (find(j, g, btoa, vis)) {
btoa[j] = i;
break;
}
}
return (int)btoa.size() - (int)count(btoa.begin(), btoa.end(), -1);
}
vi cover(vector<vi>& g, int n, int m) {
vi match(m, -1);
int res = dfsMatching(g, match);
vector<bool> lfound(n, true), seen(m);
for (int it : match)
if (it != -1)
lfound[it] = false;
vi q, cover;
for(int i = 0; i < n; i++)
if (lfound[i])
q.push_back(i);
while (!q.empty()) {
int i = q.back(); q.pop_back();
lfound[i] = 1;
for (int e : g[i]) if (!seen[e] && match[e] != -1) {
seen[e] = true;
q.push_back(match[e]);
}
}
for(int i = 0; i < n; i++)
if (!lfound[i])
cover.push_back(i);
for(int i = 0; i < m; i++)
if (seen[i])
cover.push_back(n+i);
return cover;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
vector<vector<int>> g(n);
for(int i = 1; i < n; i++){
if(protocol[i] == 0){
g[host[i]].pb(i);
}
else{
for(auto t : g[host[i]])
{
g[t].pb(i);
}
}
}
return (n-(int)cover(g, n, g.size()).size());
}