-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2251e13
commit feec8ed
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long double ld; | ||
using ll = long long; | ||
using pll = pair<ll, ll>; | ||
using ld = long double; | ||
int n, m; | ||
int a[1001]; | ||
int b[1001]; | ||
int visited[1001]; | ||
vector<int> edge[1001]; | ||
bool dfs(int pos){ | ||
visited[pos] = true; | ||
for (int nxt: edge[pos]){ | ||
if (b[nxt] == -1 || (!visited[b[nxt]] && dfs(b[nxt]))){ | ||
a[pos] = nxt; b[nxt] = pos; return true; | ||
} | ||
} | ||
return false; | ||
} | ||
void bipartite_matching() { | ||
cin >> n >> m; | ||
for (int i = 1; i <= n; i++){ | ||
int x; cin >> x; | ||
while (x--){ | ||
ll nxt; cin >> nxt; | ||
edge[i].emplace_back(nxt); | ||
} | ||
} | ||
int match = 0; | ||
memset(a, -1, sizeof(a)); | ||
memset(b, -1, sizeof(b)); | ||
for (int i = 1; i <= n; i++){ | ||
if (a[i] == -1){ | ||
memset(visited, 0, sizeof(visited)); | ||
if (dfs(i)) match++; | ||
} | ||
} | ||
return match; | ||
} |