#include<cstdio>
#include<algorithm>
#define S 1007
using namespace std;
int A[S];
int B[S];
int n,m;
int conditions[S];
int ans[S];
void f(int k){
if(k == m+1){
// for(int i = 1; i <= n; i++){
// printf("%d ",conditions[i]);
// }
// printf("\n");
int ones = 0;
for(int i = 1; i <= n; i++){
if(conditions[i] == 1){
ones++;
}
}
for(int i = 1; i <= n; i++){
int onesInside = 0;
int zerosInside = 0;
for(int j = i; j <= n; j++){
if(conditions[j] == 1)
onesInside++;
else if(conditions[j] == 0)
zerosInside++;
if(zerosInside != 0)
break;
if(onesInside != ones)
continue;
ans[j-i+1] ^= 1;
}
}
return;
}
int a = A[k];
int b = B[k];
if(conditions[a] == -1 && conditions[b] == -1){
conditions[a] = conditions[b] = 0;
f(k+1);
conditions[a] = conditions[b] = 1;
f(k+1);
conditions[a] = conditions[b] = -1;
}else if(conditions[a] == -1){
if(conditions[b] == 1){
//nothing
f(k+1);
}else{
swap(conditions[a], conditions[b]);
f(k+1);
swap(conditions[a], conditions[b]);
}
}else if(conditions[b] == -1){
if(conditions[a] == 0){
//nothing
f(k+1);
}else{
swap(conditions[a], conditions[b]);
f(k+1);
swap(conditions[a], conditions[b]);
}
}else{
if(conditions[a] == 1 && conditions[b] == 0){
swap(conditions[a], conditions[b]);
f(k+1);
swap(conditions[a], conditions[b]);
}else{
//nothing
f(k+1);
}
}
}
int main(void){
scanf("%d %d",&n,&m);
for(int i = 1; i <= m; i++){
scanf("%d %d",&A[i], &B[i]);
}
for(int i = 1; i <= n; i++){
conditions[i] = -1;
}
f(1);
for(int i = 1; i <= n; i++){
printf("%d ",ans[i]);
}
printf("\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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include<cstdio> #include<algorithm> #define S 1007 using namespace std; int A[S]; int B[S]; int n,m; int conditions[S]; int ans[S]; void f(int k){ if(k == m+1){ // for(int i = 1; i <= n; i++){ // printf("%d ",conditions[i]); // } // printf("\n"); int ones = 0; for(int i = 1; i <= n; i++){ if(conditions[i] == 1){ ones++; } } for(int i = 1; i <= n; i++){ int onesInside = 0; int zerosInside = 0; for(int j = i; j <= n; j++){ if(conditions[j] == 1) onesInside++; else if(conditions[j] == 0) zerosInside++; if(zerosInside != 0) break; if(onesInside != ones) continue; ans[j-i+1] ^= 1; } } return; } int a = A[k]; int b = B[k]; if(conditions[a] == -1 && conditions[b] == -1){ conditions[a] = conditions[b] = 0; f(k+1); conditions[a] = conditions[b] = 1; f(k+1); conditions[a] = conditions[b] = -1; }else if(conditions[a] == -1){ if(conditions[b] == 1){ //nothing f(k+1); }else{ swap(conditions[a], conditions[b]); f(k+1); swap(conditions[a], conditions[b]); } }else if(conditions[b] == -1){ if(conditions[a] == 0){ //nothing f(k+1); }else{ swap(conditions[a], conditions[b]); f(k+1); swap(conditions[a], conditions[b]); } }else{ if(conditions[a] == 1 && conditions[b] == 0){ swap(conditions[a], conditions[b]); f(k+1); swap(conditions[a], conditions[b]); }else{ //nothing f(k+1); } } } int main(void){ scanf("%d %d",&n,&m); for(int i = 1; i <= m; i++){ scanf("%d %d",&A[i], &B[i]); } for(int i = 1; i <= n; i++){ conditions[i] = -1; } f(1); for(int i = 1; i <= n; i++){ printf("%d ",ans[i]); } printf("\n"); return 0; } |
English