Created
January 28, 2021 02:57
-
-
Save nevikw39/2a61a0b07c16cdc5ebc5e82fa94f6128 to your computer and use it in GitHub Desktop.
TIOJ 1253
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
#include <bits/extc++.h> | |
using namespace std; | |
using namespace __gnu_cxx; | |
using namespace __gnu_pbds; | |
vector<int> g[1001]; | |
bool v[1001]; | |
int m[1001]; | |
bool dfs(int x) | |
{ | |
for (const int &i : g[x]) | |
{ | |
if (v[i]) | |
continue; | |
v[i] = true; | |
if (m[i] == -1 || dfs(m[i])) | |
{ | |
m[i] = x; | |
return true; | |
} | |
} | |
return false; | |
} | |
int main() | |
{ | |
ios::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n, k, t = 0; | |
while (cin >> n >> k && n && k) | |
{ | |
for (int i = 0; i <= n; i++) | |
g[i].clear(); | |
while (k--) | |
{ | |
int a, b; | |
cin >> a >> b; | |
g[a].push_back(b); | |
// g[b].push_back(a); | |
} | |
memset(m, -1, sizeof(m)); | |
int r = 0; | |
for (int i = 1; i <= n; i++) | |
{ | |
memset(v, 0, sizeof(v)); | |
r += dfs(i); | |
} | |
cout << "Case #" << ++t << ':' << r << '\n'; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment