# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
404174 | ly20 | Friend (IOI14_friend) | C++17 | 1 ms | 332 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 <bits/stdc++.h>
using namespace std;
const int MAXN = 1123;
int val[MAXN], marc[MAXN];
vector <int> grafo[MAXN];
// Find out best sample
int ld[MAXN], mtc[MAXN];
void dfs(int v) {
for(int i = 0; i < grafo[v].size(); i++) {
int viz = grafo[v][i];
if(ld[viz] != -1) continue;
ld[viz] = 1 - ld[v];
dfs(viz);
}
}
bool dfs1(int v) {
for(int i = 0; i < grafo[v].size(); i++) {
int viz = grafo[v][i];
if(marc[viz] == 1) continue;
marc[viz] = 1;
if(mtc[viz] < 0 || dfs1(mtc[viz])) {
mtc[viz] = v;
mtc[v] = viz;
return true;
}
}
return false;
}
int findSample(int n,int confidence[],int host[],int protocol[]){
for(int i = 0; i < n; i++) {
val[i] = confidence[i];
ld[i] = -1;
mtc[i] = -1;
}
for(int i = 1; i < n; i++) {
int cur = host[i];
if(protocol[i] == 0) {
grafo[i].push_back(cur);
grafo[cur].push_back(i);
}
else {
for(int j = 0; j < grafo[cur].size(); j++) {
int viz = grafo[cur][j];
grafo[viz].push_back(i);
grafo[i].push_back(viz);
}
}
}
for(int i = 0; i < n; i++) {
if(ld[i] == -1) {
ld[i] = 0;
dfs(i);
}
}
bool aux = true;
int resp = 0;
while(aux) {
for(int i = 0; i < n; i++) {
marc[i] = 0;
}
aux = false;
for(int i = 0; i < n; i++) {
if(ld[i] == 1) continue;
if(dfs1(i)) {
resp++;
aux = true;
}
}
}
return resp;
}
Compilation message (stderr)
# | 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... |