#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> steps[1003];
int tab[40];
int check(int stepNr) {
auto &step = steps[stepNr];
if(tab[step.first]==1 && tab[step.second]==0) {
return 0;
}
if(stepNr == 0) {
if(tab[step.first]==0 && tab[step.second]==1) {
return 2;
} else {
return 1;
}
}
int ret = 0;
ret += check(stepNr-1);
if(tab[step.first]==0 && tab[step.second]==1) {
tab[step.first] = 1;
tab[step.second] = 0;
ret += check(stepNr-1);
tab[step.first] = 0;
tab[step.second] = 1;
return ret;
}
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0;i<m;i++) {
int a,b;
cin >> a >> b;
steps[i] = {a-1,b-1};
}
for(int k=1;k<=n;k++) {
int ret = 0;
for(int p=0;p<=n-k;p++) {
for(int i=0;i<n;i++) {
if(i >= p && i < p+k) {
tab[i] = 1;
} else {
tab[i] = 0;
}
}
ret+=check(m-1);
}
cout << ret%2 << " ";
}
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 | #include <bits/stdc++.h> using namespace std; int n, m; pair<int, int> steps[1003]; int tab[40]; int check(int stepNr) { auto &step = steps[stepNr]; if(tab[step.first]==1 && tab[step.second]==0) { return 0; } if(stepNr == 0) { if(tab[step.first]==0 && tab[step.second]==1) { return 2; } else { return 1; } } int ret = 0; ret += check(stepNr-1); if(tab[step.first]==0 && tab[step.second]==1) { tab[step.first] = 1; tab[step.second] = 0; ret += check(stepNr-1); tab[step.first] = 0; tab[step.second] = 1; return ret; } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=0;i<m;i++) { int a,b; cin >> a >> b; steps[i] = {a-1,b-1}; } for(int k=1;k<=n;k++) { int ret = 0; for(int p=0;p<=n-k;p++) { for(int i=0;i<n;i++) { if(i >= p && i < p+k) { tab[i] = 1; } else { tab[i] = 0; } } ret+=check(m-1); } cout << ret%2 << " "; } return 0; } |
English