#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e2 + 10;
const int P = 101;
const ll MLL = 1e18;
const ll LOG = 31;
void solve() {
int n , m;
cin >> n >> m;
vector<pair<int , int>> edges(m);
vector<int> ans(n);
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
edges[i] = {a, b};
}
ll w = 1 << n;
for(int i = 1; i < w; i++) {
vector<int> init;
vector<int> cur;
int val = 0;
for(int j = 0; j < n; j++) {
ll c = 1 << j;
if(c & i){
val++;
init.push_back(1);
cur.push_back(1);
}else {
init.push_back(0);
cur.push_back(0);
}
}
for(int j = 0; j < m; j++) {
int f = edges[j].first;
int s = edges[j].second;
if(cur[f - 1] == 1 && cur[s - 1] == 0) swap(cur[f - 1], cur[s - 1]);
}
bool ok = true;
bool was = false;
for(int j = 0; j < n; j++) {
if(cur[j] == 1) {
if(was == true) ok = false;
was = true;
int h;
for(int c = j; c < n && cur[c] == 1; c++) {
h = c;
}
j = h;
}
}
if(ok) {
ans[val - 1] ^= 1;
}
}
for(int i = 0; i < n; i++) {
cout << ans[i] << " ";
}
cout <<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
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 67 68 69 70 71 72 73 74 | #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e2 + 10; const int P = 101; const ll MLL = 1e18; const ll LOG = 31; void solve() { int n , m; cin >> n >> m; vector<pair<int , int>> edges(m); vector<int> ans(n); for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; edges[i] = {a, b}; } ll w = 1 << n; for(int i = 1; i < w; i++) { vector<int> init; vector<int> cur; int val = 0; for(int j = 0; j < n; j++) { ll c = 1 << j; if(c & i){ val++; init.push_back(1); cur.push_back(1); }else { init.push_back(0); cur.push_back(0); } } for(int j = 0; j < m; j++) { int f = edges[j].first; int s = edges[j].second; if(cur[f - 1] == 1 && cur[s - 1] == 0) swap(cur[f - 1], cur[s - 1]); } bool ok = true; bool was = false; for(int j = 0; j < n; j++) { if(cur[j] == 1) { if(was == true) ok = false; was = true; int h; for(int c = j; c < n && cur[c] == 1; c++) { h = c; } j = h; } } if(ok) { ans[val - 1] ^= 1; } } for(int i = 0; i < n; i++) { cout << ans[i] << " "; } cout <<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; } |
English