# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1065344 | Mr_Husanboy | Friend (IOI14_friend) | C++17 | 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<vector>
#include <algorithm>
#include <iostream>
using namespace std;
// Find out best sample
vector<vector<int>> g;
vector<int> vis, col, mt;
void paint(int i, int c){
col[i] = c;
for(auto u : g[i]){
if(col[u]) {assert(col[u] == -c); continue;}
paint(u, -c);
}
}
bool kuhn(int i){
if(vis[i]) return false;
vis[i] = 1;
for(auto u : g[i]){
if(mt[u] == -1 || kuhn(mt[u])){
mt[u] = i;
return true;
}
}
return false;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
g.resize(n);
col.resize(n);
mt.assign(n, -1);
for(int i = 1; i < n; i ++){
if(protocol[i] == 0){
g[host[i]].push_back(i);
g[i].push_back(host[i]);
}
if(protocol[i] == 1){
for(auto u : g[host[i]]){
g[u].push_back(i);
g[i].push_back(u);
}
}
}
for(int i = 0; i < n; i ++){
if(!col[i]) paint(i, 1);
}
for(int i = 0; i < n; i ++){
if(col[i] != 1) continue;
for(auto u : g[i]){
if(mt[u] == -1){
mt[u] = i;
break;
}
}
}
for(int i = 0; i < n; i ++){
if(col[i] != 1) continue;
vis.assign(n, 0);
kuhn(i);
}
int ans = n;
for(int i = 0; i < n; i ++){
if(mt[i] != -1) ans --;
}
return ans;
}