a53

RearanjareSir

a53
Apr 10th, 2022 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <bitset>
  4.  
  5. using namespace std;
  6.  
  7. int n, A[65], B[65], c;
  8. vector <int> L[65];
  9. bitset <65> V;
  10. long long X[65];
  11.  
  12. int cupleaza(int v)
  13. {
  14. if (V[v])
  15. return 0;
  16. V[v] = 1;
  17. for (auto x: L[v])
  18. if (!B[x])
  19. {
  20. A[v] = x;
  21. B[x] = v;
  22. return 1;
  23. }
  24. for (auto x: L[v])
  25. if (cupleaza(B[x]))
  26. {
  27. A[v] = x;
  28. B[x] = v;
  29. return 1;
  30. }
  31. return 0;
  32. }
  33.  
  34. int main()
  35. {
  36. cin >> n;
  37. for (int i = 0; i < n; i++)
  38. {
  39. cin >> X[i];
  40. for (int j = 0; j < n; j++)
  41. if ((X[i] >> j) & 1)
  42. L[i + 1].push_back(j + 1);
  43. }
  44. int gata;
  45. do
  46. {
  47. gata = 1;
  48. V.reset();
  49. for (int i = 1; i <= n; i++)
  50. if (!A[i])
  51. if (cupleaza(i))
  52. {
  53. c++;
  54. gata = 0;
  55. }
  56. }
  57. while (!gata);
  58. for (int i = 1; i <= n; i++)
  59. cout << X[B[i] - 1] << " ";
  60. return 0;
  61. }
Add Comment
Please, Sign In to add comment