#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include // #include // #include // #include // using namespace __gnu_pbds; // #include // namespace multiprecisioninteger = boost::multiprecision; // using cint=multiprecisioninteger::cpp_int; using namespace std; using ll=long long; #define double long double using datas=pair; using ddatas=pair; using tdata=pair; using vec=vector; using mat=vector; using pvec=vector; using pmat=vector; // using llset=tree,rb_tree_tag,tree_order_statistics_node_update>; #define For(i,a,b) for(i=a;i<(ll)b;++i) #define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i) #define rep(i,N) For(i,0,N) #define rep1(i,N) For(i,1,N) #define brep(i,N) bFor(i,N,0) #define brep1(i,N) bFor(i,N,1) #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define vsort(v) sort(all(v)) #define vrsort(v) sort(allr(v)) #define endl "\n" #define eb emplace_back #define print(v) cout< inline bool chmax(T& a,T b){bool x=a inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} struct unionfind{ private: int maxN; vector par; public:unionfind(int N) :maxN(N),par(N){ for(int i=0;i tree; BinaryIndexedTree(int N):size(N+1),tree(size,0){} void act(int i,int x){ assert(i>=0); assert(i=0); assert(i0;i-=-i&i){ res+=tree[i]; } return res; } }; int N; vector> g; vector> pos; int euler_tour(int now,int cnt){ pos[now].first=cnt; cnt++; for(int x:g[now]){ cnt=euler_tour(x,cnt); } return pos[now].second=cnt; } int main(){ int i,Q,a,b,cnt=0; scanf("%d %d",&N,&Q); g.resize(N*2-1); pos.resize(N*2-1); unionfind tree(N*2-1); vector>> queli; while(Q--){ scanf("%d %d %d",&i,&a,&b); --a; if(i==1){ --b; a=tree.root(a); b=tree.root(b); if(a!=b){ queli.eb(1,pair(a,cnt+N)); queli.eb(1,pair(b,cnt+N)); g[cnt+N].eb(a); g[cnt+N].eb(b); tree.unite(a,cnt+N); tree.unite(b,cnt+N); ++cnt; } }else{ queli.eb(i,pair(a,b)); } } if(cnt==0){ vector v(N,0); for(auto x:queli){ if(x.first==2){ v[x.second.first]+=x.second.second; }else{ printf("%d\n",v[x.second.first]); } } return 0; } i=1; while(cnt