Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <string>
- #include <deque>
- #include <iomanip>
- #include <cstddef>
- #define F first
- #define S second
- using namespace std;
- const long double eps = 0.000000005;
- const long double pi = 3.1415926535897932;
- const long long inf = 1e9;
- vector<vector<int, int> > g;
- vector<bool> used;
- vector <int> d;
- bool try_kuhn(int v)
- {
- if (used[v])
- return false;
- used[v] = 1;
- for (int i = 0; i < g[v].size(); i++)
- {
- int to = g[v][i];
- if (d[to] == -1 || try_kuhn(d[to]))
- {
- d[to] = v;
- return true;
- }
- }
- return false;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
- // freopen("slalom.in", "r", stdin);freopen("slalom.out", "w", stdout);
- int n, m;
- cin >> n >> m;
- g.resize(n);
- for (int i = 0; i < m; i++)
- {
- cin >> x >> y;
- x--;
- y--;
- g[x].push_back(y);
- }
- d.assign(n, -1);
- int ans = 0;
- for (int i = 0; i < n; i++)
- {
- used.assign(n, 0);
- ans += try_kuhn(i);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment