Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 105;
- int n, k;
- vector<int> g[N];
- int used[N];
- int match[N];
- int timer, ans;
- bool try_kuhn(int u) {
- if(used[u] == timer) return false;
- used[u] = timer;
- for(int v : g[u]) {
- if(match[v] == 0 || try_kuhn(match[v])) {
- match[v] = u;
- return true;
- }
- }
- return false;
- }
- int main() {
- //freopen("in.txt", "r", stdin);
- //freopen("MATCH1.inp", "r", stdin);
- //freopen("MATCH1.out", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- cin >> n >> k;
- int u, v;
- while(cin >> u >> v) {
- g[u].push_back(v);
- }
- timer = ans = 0;
- for(int i = 1; i <= n; ++i) {
- timer++;
- ans += try_kuhn(i);
- }
- cout << ans << '\n';
- for(int i = 1; i <= k; ++i) {
- if(match[i])
- cout << match[i] << ' ' << i << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment