//#define _GLIBCXX_DEBUG #include using namespace std; #define endl '\n' #define lfs cout<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair; templatebool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} templatebool chmax(T1 &a,T2 b){if(avoid ans(bool x,T1 y,T2 z){if(x)cout<void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;ivoid debug(vector&v,ll n){if(n!=0)cout<vector>vec(ll x, ll y, T w){vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,-1,0,0,1,1,-1,-1};vectordy={0,0,1,-1,1,-1,1,-1}; templatevector make_v(size_t a,T b){return vector(a,b);} templateauto make_v(size_t a,Ts... ts){return vector(a,make_v(ts...));} templateostream &operator<<(ostream &os, const pair&p){return os << p.first << " " << p.second;} templateostream &operator<<(ostream &os, const vector &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;} templatevoid rearrange(vector&ord, vector&v){ auto tmp = v; for(int i=0;ivoid rearrange(vector&ord,Head&& head, Tail&&... tail){ rearrange(ord, head); rearrange(ord, tail...); } //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int popcount(ll x){return __builtin_popcountll(x);}; int poplow(ll x){return __builtin_ctzll(x);}; int pophigh(ll x){return 63 - __builtin_clzll(x);}; struct MergeTree{ vector data; vectorcurrent; vector> graph; vectorin, out; vectorord; int num; int time; MergeTree(int size) : data(size, -1), current(size), graph(size), time(size - 1), num(size){ iota(current.begin(), current.end(), 0); } int unite(int x, int y) { x = root(x); y = root(y); if(x != y){ graph.emplace_back(); time++; graph[time].push_back(current[x]); graph[time].push_back(current[y]); if (data[y] < data[x]) swap(x, y); current[x] = time; data[x] += data[y]; data[y] = x; num--; } return time; } void build(){ graph.emplace_back(); in.resize(graph.size()); out.resize(graph.size()); time++; for(int i = 0; i < data.size(); i++){ if(root(i) == i)graph[time].push_back(current[i]); } int t = 0; build_dfs(time, t); } void build_dfs(int pos, int &t){ in[pos] = t; if(graph[pos].size() == 0){ ord.push_back(pos); t++; } for(auto to:graph[pos]){ build_dfs(to, t); } out[pos] = t; } int component(int x){ return current[root(x)]; } bool find(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; template struct BIT{ ll n; ll k=1; vectordata; BIT() = default; BIT(ll size):n(size){ n++; data.assign(n,0); while(k*2<=n)k*=2; } void add(ll a,T w){ for(ll i=a+1;i<=n;i+=i&-i)data[i-1]+=w; } void add(ll l,ll r,T w){ add(l,w);add(r+1,-w); } T sum(ll a){ if(a<0)return 0; T ret = 0; for(ll i=a+1;i>0;i-=i&-i)ret+=data[i-1]; return ret; } T sum(ll a,ll b){return a>b?0:sum(b)-sum(a-1);} T operator[](ll pos){ return sum(pos,pos); } ll lower_bound(ll x){ ll ret=0; for(ll i=k;i>0;i/=2){ if(ret+i<=n&&data[ret+i-1]>n>>q; MergeTree uf(n); vectort(q),a(q),b(q),c(q); rep(i,0,q){ cin>>t[i]>>a[i]>>b[i]; if(t[i]==1){ a[i]--;b[i]--; uf.unite(a[i],b[i]); } if(t[i]==2){ a[i]--; c[i]=uf.component(a[i]); } if(t[i]==3){ a[i]--; c[i]=uf.component(a[i]); } } uf.build(); BITbit(n); rep(i,0,q){ if(t[i]==1)continue; if(t[i]==2){ bit.add(uf.in[c[i]],uf.out[c[i]]-1,b[i]); } else cout<