#include <iostream>
#include <vector>
std::vector<std::pair<int, int>> rozkazy;
long long ans[36];
bool zol[36];
int n, m, counter = 1;
void search(int x) {
if (x == -1)
ans[counter]++;
else if(!zol[rozkazy[x].first] || zol[rozkazy[x].second]) {
if (!zol[rozkazy[x].first] && zol[rozkazy[x].second]) {
zol[rozkazy[x].first] = true;
zol[rozkazy[x].second] = false;
search(x - 1);
zol[rozkazy[x].first] = false;
zol[rozkazy[x].second] = true;
}
search(x - 1);
}
}
int main()
{
std::ios_base::sync_with_stdio();
std::cin.tie(0);
std::cin >> n >> m;
int a, b;
for (int i = 0; i < m; i++) {
std::cin >> a >> b;
rozkazy.push_back({ a, b });
}
while (counter <= n) {
for (int j = 0; j < counter; j++)
zol[j] = true;
for (int j = counter; j <= n; j++) {
zol[j] = true;
zol[j - counter] = false;
search(rozkazy.size() - 1);
}
for (int j = n; j > n - counter; j--)
zol[j] = false;
counter++;
}
for (int i = 1; i <= n; i++)
std::cout << ans[i] % 2 << ' ';
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <vector> std::vector<std::pair<int, int>> rozkazy; long long ans[36]; bool zol[36]; int n, m, counter = 1; void search(int x) { if (x == -1) ans[counter]++; else if(!zol[rozkazy[x].first] || zol[rozkazy[x].second]) { if (!zol[rozkazy[x].first] && zol[rozkazy[x].second]) { zol[rozkazy[x].first] = true; zol[rozkazy[x].second] = false; search(x - 1); zol[rozkazy[x].first] = false; zol[rozkazy[x].second] = true; } search(x - 1); } } int main() { std::ios_base::sync_with_stdio(); std::cin.tie(0); std::cin >> n >> m; int a, b; for (int i = 0; i < m; i++) { std::cin >> a >> b; rozkazy.push_back({ a, b }); } while (counter <= n) { for (int j = 0; j < counter; j++) zol[j] = true; for (int j = counter; j <= n; j++) { zol[j] = true; zol[j - counter] = false; search(rozkazy.size() - 1); } for (int j = n; j > n - counter; j--) zol[j] = false; counter++; } for (int i = 1; i <= n; i++) std::cout << ans[i] % 2 << ' '; } |
English