#include<bits/stdc++.h> using namespace std; typedef pair<int, int> par; par moves[1009]; int tab[40]; long long sym(int i) { if(i == 0) return 1; int a = moves[i].first, b = moves[i].second; if(tab[a] == tab[b]) return sym(i-1); if(tab[a] == 1 && tab[b] == 0) return 0; long long c = sym(i-1); tab[a] = 1; tab[b] = 0; c += sym(i-1); tab[a] = 0; tab[b] = 1; return c; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, a, b; cin>>n>>m; for(int i=1; i<=m; i++) { cin>>a>>b; moves[i] = par(a, b); } for(int k=1; k<=n; k++) { a = 0; for(int i=1; i<=k; i++) tab[i] = 1; for(int i=k+1; i<=n; i++) tab[i] = 0; for(int i=1; i<=n-k+1; i++) { b = sym(m); a += b; tab[i] = 0; tab[i+k] = 1; } cout<<a%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 | #include<bits/stdc++.h> using namespace std; typedef pair<int, int> par; par moves[1009]; int tab[40]; long long sym(int i) { if(i == 0) return 1; int a = moves[i].first, b = moves[i].second; if(tab[a] == tab[b]) return sym(i-1); if(tab[a] == 1 && tab[b] == 0) return 0; long long c = sym(i-1); tab[a] = 1; tab[b] = 0; c += sym(i-1); tab[a] = 0; tab[b] = 1; return c; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, m, a, b; cin>>n>>m; for(int i=1; i<=m; i++) { cin>>a>>b; moves[i] = par(a, b); } for(int k=1; k<=n; k++) { a = 0; for(int i=1; i<=k; i++) tab[i] = 1; for(int i=k+1; i<=n; i++) tab[i] = 0; for(int i=1; i<=n-k+1; i++) { b = sym(m); a += b; tab[i] = 0; tab[i+k] = 1; } cout<<a%2<<" "; } return 0; } |