Advertisement
Ne-Biolog

Untitled

May 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory.h>
  4. #include <iterator>
  5. #include <cassert>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <cstdlib>
  9. #include <bitset>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <string>
  13. #include <queue>
  14. #include <deque>
  15. #include <cmath>
  16. #include <ctime>
  17. #include <stack>
  18. #include <set>
  19. #include <map>
  20.  
  21. using namespace std;
  22.  
  23. const int N = (int)5000 + 10;
  24. const int INF = (int)1e9 + 10;
  25.  
  26. int n, k, m;
  27. vector < vector<int> > g;
  28. vector<int> mt;
  29. vector<char> used;
  30.  
  31. bool try_kuhn (int v) {
  32. if (used[v]) return false;
  33. used[v] = true;
  34. for (size_t i = 0; i < g[v].size(); ++i) {
  35. int to = g[v][i];
  36. if (mt[to] == -1 || try_kuhn (mt[to])) {
  37. mt[to] = v;
  38. return true;
  39. }
  40. }
  41. return false;
  42. }
  43.  
  44. int main ()
  45. {
  46. freopen("input.txt" , "r" , stdin);
  47. //freopen("output.txt" , "w" , stdout);
  48. ios_base::sync_with_stdio(false);
  49.  
  50. cin >> n >> k;
  51. for(int i = 0; i < k; ++i) {
  52. for(int j = 0; j < n; ++j) {
  53. int x; cin >> x;
  54. if(x == 1) {
  55. g[i].push_back(j);
  56. }
  57. }
  58. }
  59.  
  60. mt.assign (k, -1);
  61. for (int v = 0; v < n; ++v) {
  62. used.assign (n, false);
  63. try_kuhn (v);
  64. }
  65.  
  66. for (int i = 0; i < k; ++i)
  67. if (mt[i] != -1)
  68. printf ("%d %d\n", mt[i]+1, i+1);
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement