Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef pair<int, int> pii;
- typedef long double ld;
- vector<vector<int>> g;
- vector<bool> used;
- vector<int> mpair(1001, -1);
- bool kuhn(int v) {
- if (used[v]) return false;
- used[v] = true;
- for (auto u : g[v]) {
- if (mpair[u] == -1 || kuhn(mpair[u])) {
- mpair[u] = v;
- return true;
- }
- }
- return false;
- }
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- freopen("paths.in", "r", stdin);
- freopen("paths.out", "w", stdout);
- int n, m;
- cin >> n >> m;
- g.resize(n + 1);
- for (int i = 0; i < m; i++) {
- int u, v;
- cin >> v >> u;
- g[v].push_back(u);
- }
- used.resize(n + 1, false);
- for (int i = 1; i <= n; i++) {
- used.assign(n + 1, false);
- kuhn(i);
- }
- int cnt = 0;
- for (int i = 0; i < n + 1; i++) {
- if (mpair[i] != -1) {
- cnt++;
- }
- }
- cout << n - cnt << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement