#define PROB Problema4 #include #include #include #include #include using namespace std; typedef int var; #define fin cin #define fout cout //ifstream fin("date.in"); //ofstream fout("date.out"); #define MAXN 100005 bool TRUE[MAXN]; var TREE[MAXN]; const var zeros(var val) { return val & (-val); } void update(var ind, var val) { for(;ind>n>>m; while(m--) { fin>>type; if(type == 1) { fin>>a>>b; timp++; update_int(timp, timp, 1); ++time_index; TIMES[time_index] = timp; if(query(INIT[a]) == 0) { INIT[a] = timp; } if(query(INIT[b]) == 0) { INIT[b] = timp; } var r1 = Find(a), r2 = Find(b); if(r1 != r2) { Union(r1, r2, timp); } } else if(type == 2) { fin>>a; var it = 0; time_index -= a; update_int(TIMES[time_index]+1, timp, -1); } else { fin>>a>>b; if(a == b) { if(query(INIT[a]) <= 0) { fout<<"0\n"; } else { fout<<"1\n"; } } else { fout<<(Find(a) == Find(b))<<'\n'; } } } }