#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 40; ll ans[MAXN]; vector<pair<int, int>> vec; ll is[MAXN]; int n, m; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; int u, v; for(int i = 1; i <= m; i++){ cin >> u >> v; u--; v--; vec.push_back({u, v}); } for(int i = 1; i < (1 << n); i++){ for(int j = 0; j < n; j++){ is[j] = 0; if(i & (1 << j)){ is[j] = 1; } } for(int j = 0; j < m; j++){ if(is[vec[j].first] == 1 && is[vec[j].second] == 0){ is[vec[j].second] = 1; is[vec[j].first] = 0; } } bool ok = true, was1 = false, pos = true; for(int j = 0; j < n; j++){ if(is[j] == 1 && pos == false){ ok = false; was1 = true; }else if(is[j] == 1){ was1 = true; }else if(is[j] == 0){ if(was1){ pos = false; } } } if(ok){ ans[__builtin_popcount(i)]++; ans[__builtin_popcount(i)] %= 2; } } for(int i = 1; i <= n; i++){ cout << ans[i] % 2 << ' '; } cout << '\n'; return 0; }
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 | #include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 40; ll ans[MAXN]; vector<pair<int, int>> vec; ll is[MAXN]; int n, m; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; int u, v; for(int i = 1; i <= m; i++){ cin >> u >> v; u--; v--; vec.push_back({u, v}); } for(int i = 1; i < (1 << n); i++){ for(int j = 0; j < n; j++){ is[j] = 0; if(i & (1 << j)){ is[j] = 1; } } for(int j = 0; j < m; j++){ if(is[vec[j].first] == 1 && is[vec[j].second] == 0){ is[vec[j].second] = 1; is[vec[j].first] = 0; } } bool ok = true, was1 = false, pos = true; for(int j = 0; j < n; j++){ if(is[j] == 1 && pos == false){ ok = false; was1 = true; }else if(is[j] == 1){ was1 = true; }else if(is[j] == 0){ if(was1){ pos = false; } } } if(ok){ ans[__builtin_popcount(i)]++; ans[__builtin_popcount(i)] %= 2; } } for(int i = 1; i <= n; i++){ cout << ans[i] % 2 << ' '; } cout << '\n'; return 0; } |