// Witold Milewski // PA 2024 #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i=a; i<=b; ++i) #define pb push_back #define pi pair<int, int> #define f first #define s second vector<pi> changes; const int maxn=36; int odp[maxn]; int n, m; void solve(int msk) { vector<int> num(n+2, 0); int cnt=0; FOR(i, 0, n-1) if(msk&(1<<i)) num[i+1]=1, ++cnt; for(auto &[a, b] : changes) if(num[a] && !num[b]) swap(num[a], num[b]); int idx=1; while(idx<=n) { if(num[idx]) break; ++idx; } int start=idx; ++idx; while(idx<=n+1) { if(!num[idx]) break; ++idx; } int koniec=idx-1; int dl = koniec-start+1; if(dl != cnt) return; odp[dl]=1-odp[dl]; } int main() { cin.tie(0) -> ios_base::sync_with_stdio(0); cin >> n >> m; int a, b; FOR(i, 1, m) { cin >> a >> b; changes.pb({a, b}); } FOR(i, 1, (1<<n)-1) solve(i); FOR(i, 1, n) cout << odp[i] << ' '; cout << '\n'; }
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 | // Witold Milewski // PA 2024 #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i=a; i<=b; ++i) #define pb push_back #define pi pair<int, int> #define f first #define s second vector<pi> changes; const int maxn=36; int odp[maxn]; int n, m; void solve(int msk) { vector<int> num(n+2, 0); int cnt=0; FOR(i, 0, n-1) if(msk&(1<<i)) num[i+1]=1, ++cnt; for(auto &[a, b] : changes) if(num[a] && !num[b]) swap(num[a], num[b]); int idx=1; while(idx<=n) { if(num[idx]) break; ++idx; } int start=idx; ++idx; while(idx<=n+1) { if(!num[idx]) break; ++idx; } int koniec=idx-1; int dl = koniec-start+1; if(dl != cnt) return; odp[dl]=1-odp[dl]; } int main() { cin.tie(0) -> ios_base::sync_with_stdio(0); cin >> n >> m; int a, b; FOR(i, 1, m) { cin >> a >> b; changes.pb({a, b}); } FOR(i, 1, (1<<n)-1) solve(i); FOR(i, 1, n) cout << odp[i] << ' '; cout << '\n'; } |