double_trouble

Кунн

Feb 26th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <cmath>
  6. #include <string>
  7. #include <algorithm>
  8. #include <string>
  9. #include <deque>
  10. #include <iomanip>
  11. #include <cstddef>
  12.  
  13. #define F first
  14. #define S second
  15.  
  16. using namespace std;
  17.  
  18.  
  19. const long double eps = 0.000000005;
  20. const long double pi = 3.1415926535897932;
  21. const long long inf = 1e9;
  22.  
  23. vector<vector<int, int> > g;
  24. vector<bool> used;
  25. vector <int> d;
  26.  
  27. bool try_kuhn(int v)
  28. {
  29.     if (used[v])
  30.         return false;
  31.     used[v] = 1;
  32.     for (int i = 0; i < g[v].size(); i++)
  33.     {
  34.         int to = g[v][i];
  35.         if (d[to] == -1 || try_kuhn(d[to]))
  36.         {
  37.             d[to] = v;
  38.             return true;
  39.         }
  40.     }
  41.     return false;
  42. }
  43.  
  44. int main()
  45. {
  46.     ios_base::sync_with_stdio(0);
  47.     //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
  48.     // freopen("slalom.in", "r", stdin);freopen("slalom.out", "w", stdout);
  49.  
  50.     int n, m;
  51.     cin >> n >> m;
  52.     g.resize(n);
  53.     for (int i = 0; i < m; i++)
  54.     {
  55.         cin >> x >> y;
  56.         x--;
  57.         y--;
  58.         g[x].push_back(y);
  59.     }
  60.  
  61.     d.assign(n, -1);
  62.     int ans = 0;
  63.     for (int i = 0; i < n; i++)
  64.     {
  65.         used.assign(n, 0);
  66.         ans += try_kuhn(i);
  67.     }
  68.  
  69.     return 0;
  70. }
Add Comment
Please, Sign In to add comment