Guest User

Untitled

a guest
May 18th, 2020
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, m, a, b, s, k;
  6. vector<vector<int> > lef;
  7. vector<int> righ;
  8. vector<int> used;
  9.  
  10. bool dfs(int now) {
  11. if (used[now] == 1) {
  12. return false;
  13. }
  14. used[now] = 1;
  15. for (auto j : lef[now]) {
  16. if (righ[j] == -1 || dfs(righ[j])) {
  17. righ[j] = now;
  18. return true;
  19. }
  20. }
  21. return false;
  22. }
  23.  
  24. int main() {
  25. cin >> n >> m >> k;
  26. lef.resize(n);
  27. righ.resize(m, -1);
  28. used.resize(n);
  29. for (int i = 0; i < k; i++) {
  30. cin >> a >> b;
  31. lef[a - 1].push_back(b - 1);
  32. }
  33. for (int i = 0; i < n; i++) {
  34. fill(used.begin(), used.end(), 0);
  35. dfs(i);
  36. }
  37. long long ans = 0;
  38. for (int i = 0; i < m; i++) {
  39. if (righ[i] != -1) {
  40. ans++;
  41. }
  42. }
  43. cout << ans << endl;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment