#include<bits/stdc++.h> using namespace std; int n,m; pair<int,int> orders[1010]; int ans[40]; int f1(long long msol){ queue<long long> que[2]; que[(m-1)&1].push(msol); long long tsol; long long pos1,pos2; for(int i = m - 1; i >= 0; i--){ pos1 = (1LL << orders[i].first); pos2 = (1LL << orders[i].second); while(!que[i&1].empty()){ tsol = que[i&1].front(); que[i&1].pop(); if(tsol & pos1){ if(tsol & pos2){ que[(i+1)&1].push(tsol); } } else { if(tsol & pos2){ que[(i+1)&1].push(tsol); que[(i+1)&1].push(tsol - pos2 + pos1); } else { que[(i+1)&1].push(tsol); } } } } return que[1].size(); } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m; for(int i = 0; i < m; i++){ cin >> orders[i].first >> orders[i].second; orders[i].first--; orders[i].second--; } long long mask; for(int i = 0; i < n; i++){ mask = (1LL << i); for(int j = i + 1; j < n; j++){ mask |= (1LL << j); ans[j - i + 1] += f1(mask); } } ans[1] = n; for(int i = 1; i <= n; i++){ cout << (ans[i]&1) << " "; } cout << "\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 | #include<bits/stdc++.h> using namespace std; int n,m; pair<int,int> orders[1010]; int ans[40]; int f1(long long msol){ queue<long long> que[2]; que[(m-1)&1].push(msol); long long tsol; long long pos1,pos2; for(int i = m - 1; i >= 0; i--){ pos1 = (1LL << orders[i].first); pos2 = (1LL << orders[i].second); while(!que[i&1].empty()){ tsol = que[i&1].front(); que[i&1].pop(); if(tsol & pos1){ if(tsol & pos2){ que[(i+1)&1].push(tsol); } } else { if(tsol & pos2){ que[(i+1)&1].push(tsol); que[(i+1)&1].push(tsol - pos2 + pos1); } else { que[(i+1)&1].push(tsol); } } } } return que[1].size(); } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m; for(int i = 0; i < m; i++){ cin >> orders[i].first >> orders[i].second; orders[i].first--; orders[i].second--; } long long mask; for(int i = 0; i < n; i++){ mask = (1LL << i); for(int j = i + 1; j < n; j++){ mask |= (1LL << j); ans[j - i + 1] += f1(mask); } } ans[1] = n; for(int i = 1; i <= n; i++){ cout << (ans[i]&1) << " "; } cout << "\n"; return 0; } |