#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
using namespace std;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define x first
#define y second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
pii moves[1001];
bool ans[36];
vll valid[36];
int n, m;
inline bool dfs(ll c, int cur_move){
if(cur_move==-1){
return true;
}
ll a = ( 1LL << (moves[cur_move].st-1) );
ll b = ( 1LL << (moves[cur_move].nd-1) );
bool ac = c & a;
bool bc = c & b;
if((ac && bc) || (!ac && !bc)){
return dfs(c, cur_move-1);
}else if(!ac && bc){
return (dfs(c, cur_move-1) + dfs(c^a^b, cur_move-1)) & 1;
}else{
return false;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for(int i=0; i<m; i++){
int a, b;
cin >> a >> b;
moves[i] = mp(a, b);
}
for(int i=1; i<=n; i++){
for(int j=0; j<n-i+1; j++){
ll c = ((1LL << i) -1) << j;
valid[i].pb(c);
}
}
for(int i=1; i<=n; i++){
for(auto c: valid[i]){
ans[i] = (ans[i] + dfs(c, m-1)) & 1;
}
cout << ans[i] << " ";
}
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 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> #include <unordered_map> #include <unordered_set> #include <tuple> using namespace std; #define pb push_back #define mp make_pair #define st first #define nd second #define x first #define y second typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; pii moves[1001]; bool ans[36]; vll valid[36]; int n, m; inline bool dfs(ll c, int cur_move){ if(cur_move==-1){ return true; } ll a = ( 1LL << (moves[cur_move].st-1) ); ll b = ( 1LL << (moves[cur_move].nd-1) ); bool ac = c & a; bool bc = c & b; if((ac && bc) || (!ac && !bc)){ return dfs(c, cur_move-1); }else if(!ac && bc){ return (dfs(c, cur_move-1) + dfs(c^a^b, cur_move-1)) & 1; }else{ return false; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for(int i=0; i<m; i++){ int a, b; cin >> a >> b; moves[i] = mp(a, b); } for(int i=1; i<=n; i++){ for(int j=0; j<n-i+1; j++){ ll c = ((1LL << i) -1) << j; valid[i].pb(c); } } for(int i=1; i<=n; i++){ for(auto c: valid[i]){ ans[i] = (ans[i] + dfs(c, m-1)) & 1; } cout << ans[i] << " "; } cout << "\n"; return 0; } |
English