Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <bitset>
- using namespace std;
- int n, A[65], B[65], c;
- vector <int> L[65];
- bitset <65> V;
- long long X[65];
- int cupleaza(int v)
- {
- if (V[v])
- return 0;
- V[v] = 1;
- for (auto x: L[v])
- if (!B[x])
- {
- A[v] = x;
- B[x] = v;
- return 1;
- }
- for (auto x: L[v])
- if (cupleaza(B[x]))
- {
- A[v] = x;
- B[x] = v;
- return 1;
- }
- return 0;
- }
- int main()
- {
- cin >> n;
- for (int i = 0; i < n; i++)
- {
- cin >> X[i];
- for (int j = 0; j < n; j++)
- if ((X[i] >> j) & 1)
- L[i + 1].push_back(j + 1);
- }
- int gata;
- do
- {
- gata = 1;
- V.reset();
- for (int i = 1; i <= n; i++)
- if (!A[i])
- if (cupleaza(i))
- {
- c++;
- gata = 0;
- }
- }
- while (!gata);
- for (int i = 1; i <= n; i++)
- cout << X[B[i] - 1] << " ";
- return 0;
- }
Add Comment
Please, Sign In to add comment