#include<iostream> #include<vector> #include<algorithm> #include<tuple> using namespace std; typedef pair<uint, uint> pii; typedef unsigned long long int ull; vector<pii> roz; ull n, m; ull res(ull num, ull r){ if(r == m) return 1; ull ret = 0; ull a, b; tie(a, b) = roz[r]; ull a1 = num&(1ULL<<a); ull b1 = num&(1ULL<<b); if(a1 > 0 and b1 == 0){ return 0; } if(a1 == 0 and b1 > 0){ ull cnum = num; cnum |= 1ULL<<a; cnum &= ~(1ULL<<b); ret += res(cnum, r+1); } ret += res(num, r+1); return ret%2; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for(ull i = 0 ; i < m ; i ++){ ull a, b; cin >> a >> b; a = n - a; b = n - b; roz.push_back({a, b}); } reverse(roz.begin(), roz.end()); for(ull i = 1; i <= n; i++){ ull start = 0; start = (1LL<<(i))-1; ull r = 0; for(ull k = 0; k <= (n-i); k++){ r += res(start, 0); start <<= 1; } cout << r%2 << " "; } cout << endl; 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<iostream> #include<vector> #include<algorithm> #include<tuple> using namespace std; typedef pair<uint, uint> pii; typedef unsigned long long int ull; vector<pii> roz; ull n, m; ull res(ull num, ull r){ if(r == m) return 1; ull ret = 0; ull a, b; tie(a, b) = roz[r]; ull a1 = num&(1ULL<<a); ull b1 = num&(1ULL<<b); if(a1 > 0 and b1 == 0){ return 0; } if(a1 == 0 and b1 > 0){ ull cnum = num; cnum |= 1ULL<<a; cnum &= ~(1ULL<<b); ret += res(cnum, r+1); } ret += res(num, r+1); return ret%2; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; for(ull i = 0 ; i < m ; i ++){ ull a, b; cin >> a >> b; a = n - a; b = n - b; roz.push_back({a, b}); } reverse(roz.begin(), roz.end()); for(ull i = 1; i <= n; i++){ ull start = 0; start = (1LL<<(i))-1; ull r = 0; for(ull k = 0; k <= (n-i); k++){ r += res(start, 0); start <<= 1; } cout << r%2 << " "; } cout << endl; return 0; } |