#include<bits/stdc++.h>
using namespace std;
const int n_max = 1007;
vector<pair<int, int>> order;
vector<bitset<35>> positions[n_max];
int ans[n_max];
vector<string> tab;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
a--;
b--;
order.push_back({a, b});
}
bitset<35> wzor;
//string wzor = "0000";
// for(int i = 0; i < n; i++){
// wzor[i] = '1';
// positions[0].push_back(wzor);
// }
// for(int i = 0; i < n - 1; i++){
// wzor[i] = '0';
// positions[0].push_back(wzor);
// }
for(int i = 0; i < n; i++){
wzor.reset();
for(int j = i; j < n; j++){
wzor[j] = '1';
positions[0].push_back(wzor);
}
}
// tab.push_back("Basie");
// tab.push_back("Kota");
// tab.push_back("Ala");
// sort(tab.begin(), tab.end());
// for(auto u: tab){
// cout << u << '\n';
// }
reverse(order.begin(), order.end());
for(int i = 0; i < m; i++){
auto [a, b] = order[i];
// string last = "#";
//sort(positions[i].begin(), positions[i].end());
for(auto u: positions[i]){
// if(u == last){
// continue;
// }else{
// last = u;
// }
if((u[a] == 0 and u[b] == 0) or (u[a] == 1 and u[b] == 1)){
positions[i+1].push_back(u);
continue;
}
if(u[b] == 1){
positions[i+1].push_back(u);
u[a] = 1;
u[b] = 0;
positions[i+1].push_back(u);
}
}
positions[i].clear();
}
for(auto u: positions[m]){
int id = u.count();
// for(auto v: u){
// if(v == '1'){
// id++;
// }
// }
ans[id] = (ans[id] + 1)%2;
}
for(int i = 1; i <= n; i++){
cout << ans[i] << ' ';
}
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 | #include<bits/stdc++.h> using namespace std; const int n_max = 1007; vector<pair<int, int>> order; vector<bitset<35>> positions[n_max]; int ans[n_max]; vector<string> tab; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--; b--; order.push_back({a, b}); } bitset<35> wzor; //string wzor = "0000"; // for(int i = 0; i < n; i++){ // wzor[i] = '1'; // positions[0].push_back(wzor); // } // for(int i = 0; i < n - 1; i++){ // wzor[i] = '0'; // positions[0].push_back(wzor); // } for(int i = 0; i < n; i++){ wzor.reset(); for(int j = i; j < n; j++){ wzor[j] = '1'; positions[0].push_back(wzor); } } // tab.push_back("Basie"); // tab.push_back("Kota"); // tab.push_back("Ala"); // sort(tab.begin(), tab.end()); // for(auto u: tab){ // cout << u << '\n'; // } reverse(order.begin(), order.end()); for(int i = 0; i < m; i++){ auto [a, b] = order[i]; // string last = "#"; //sort(positions[i].begin(), positions[i].end()); for(auto u: positions[i]){ // if(u == last){ // continue; // }else{ // last = u; // } if((u[a] == 0 and u[b] == 0) or (u[a] == 1 and u[b] == 1)){ positions[i+1].push_back(u); continue; } if(u[b] == 1){ positions[i+1].push_back(u); u[a] = 1; u[b] = 0; positions[i+1].push_back(u); } } positions[i].clear(); } for(auto u: positions[m]){ int id = u.count(); // for(auto v: u){ // if(v == '1'){ // id++; // } // } ans[id] = (ans[id] + 1)%2; } for(int i = 1; i <= n; i++){ cout << ans[i] << ' '; } return 0; } |
English