-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmax-not-present.cpp
More file actions
51 lines (42 loc) · 888 Bytes
/
max-not-present.cpp
File metadata and controls
51 lines (42 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <vector>
using namespace std;
vector<vector<int>> G;
vector<int> seen;
vector<int> match;
int iteration = -1;
int bpm(int u) {
for (int v : G[u])
if (seen[v] != iteration) {
seen[v] = iteration;
if (match[v] == -1 || bpm(match[v])) {
match[v] = u;
return true;
}
}
return false;
}
int solution(vector<int> &A, vector<int> &B) {
G.resize(A.size() + 1);
for (int i = 0; i < A.size(); i++) {
if (A[i] < G.size())
G[A[i]].push_back(i);
if (B[i] < G.size())
G[B[i]].push_back(i);
}
seen.resize(A.size(), -1);
match.resize(A.size(), -1);
int sol = 0;
for (int i = 1; i < G.size(); i++) {
iteration = i;
if (bpm(i))
sol++;
else
break;
}
return sol + 1;
}
int main() { return 0; }
/**
* Submission link:
* https://app.codility.com/demo/results/trainingB7V9GY-GXP/
*/