#include <iostream>
#include <vector>
using namespace std;
using u64 = unsigned long long;
struct Order {
u64 a, b;
};
struct TestCase {
u64 n, m;
vector<Order> orders;
};
TestCase read_test_case() {
TestCase tc;
cin >> tc.n >> tc.m;
tc.orders.resize(tc.m);
for (auto& o : tc.orders) {
cin >> o.a >> o.b;
o.a--;
o.b--;
}
return tc;
}
void solve_test_case(TestCase tc);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve_test_case(read_test_case());
}
const u64 ONE = 1;
void solve_test_case(TestCase tc) {
vector<u64> result(tc.n, 0);
for (u64 i = 1; i < ONE << tc.n; i++) {
u64 x = i;
for (const auto [a, b] : tc.orders) {
if ((x & (ONE << a)) != 0 && (x & (ONE << b)) == 0) {
x -= (ONE << a);
x += (ONE << b);
}
}
int first = -1;
int last = -1;
for (u64 j = 0; j < tc.n; j++) {
if ((x & (ONE << j)) != 0) {
if (first == -1) first = j;
last = j;
}
}
if (__builtin_popcount(i) == last - first + 1) {
result[last - first]++;
}
}
for (auto x : result) cout << x % 2 << " ";
cout << "\n";
}
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include <iostream> #include <vector> using namespace std; using u64 = unsigned long long; struct Order { u64 a, b; }; struct TestCase { u64 n, m; vector<Order> orders; }; TestCase read_test_case() { TestCase tc; cin >> tc.n >> tc.m; tc.orders.resize(tc.m); for (auto& o : tc.orders) { cin >> o.a >> o.b; o.a--; o.b--; } return tc; } void solve_test_case(TestCase tc); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve_test_case(read_test_case()); } const u64 ONE = 1; void solve_test_case(TestCase tc) { vector<u64> result(tc.n, 0); for (u64 i = 1; i < ONE << tc.n; i++) { u64 x = i; for (const auto [a, b] : tc.orders) { if ((x & (ONE << a)) != 0 && (x & (ONE << b)) == 0) { x -= (ONE << a); x += (ONE << b); } } int first = -1; int last = -1; for (u64 j = 0; j < tc.n; j++) { if ((x & (ONE << j)) != 0) { if (first == -1) first = j; last = j; } } if (__builtin_popcount(i) == last - first + 1) { result[last - first]++; } } for (auto x : result) cout << x % 2 << " "; cout << "\n"; } |
English