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 <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 1e5 + 10;
vector<vector<int>> g;
vector<int> vis, col;
vector<int> match;
void dfs(int u, vector<int> &L, vector<int> &R) {
vis[u] = 1;
if(!col[u]) L.push_back(u);
else R.push_back(u);
for(int v : g[u]) {
if(vis[v]) continue ;
col[v] = col[u] ^ 1;
dfs(v, L, R);
}
}
int DFS(int u) {
if(vis[u]) return 0;
vis[u] = 1;
for(int v : g[u]) {
if(match[v] == -1 || DFS(match[v])) {
match[v] = u;
return 1;
}
}
return 0;
}
int sub(int n) {
vis.resize(n);
col.resize(n);
match.resize(n);
for(int i = 0; i < n; i ++) {
vis[i] = 0;
col[i] = 0;
}
int total = 0;
for(int i = 0; i < n; i ++) {
if(vis[i]) continue ;
vector<int> L, R;
dfs(i, L, R);
for(int x : R) match[x] = -1;
for(int x : L) {
for(int y : L) {
vis[y] = 0;
}
DFS(x);
}
for(int x : R) total += match[x] != -1;
}
return n - total;
}
int findSample(int n, int confidence[], int host[], int protocol[]){
g.resize(n);
for(int i = 1; i < n; i ++) {
int p = host[i];
if(protocol[i] == 0 || protocol[i] == 2) {
g[i].push_back(p);
g[p].push_back(i);
}
if(protocol[i] == 1 || protocol[i] == 2) {
for(int v : g[p]) {
g[i].push_back(v);
g[v].push_back(i);
}
}
}
return sub(n);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |