//#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; template bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} template bool chmax(T1 &a,T2 b){if(a void 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;i void 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,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } template ostream &operator<<(ostream &os, const pair&p){ return os << p.first << " " << p.second; } //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); struct WeightedUnionFind { vector data; vector difweight; WeightedUnionFind(ll size){ data.assign(size,-1); difweight.assign(size,0); } bool unite(ll x, ll y, ll w) { //y=x+w w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y), w = -w; data[x] += data[y]; data[y] = x; difweight[y] = w; } return x != y; } bool find(ll x, ll y) { return root(x) == root(y); } ll diff(ll x,ll y){//y-x return weight(y)-weight(x); } ll weight(ll x){ //根との相対位置 root(x); return difweight[x]; } ll root(ll x) { if(data[x] < 0){ return x; } else{ ll tmp = root(data[x]); difweight[x] += difweight[data[x]]; return data[x] = tmp; } } ll size(ll x) { return -data[root(x)]; } ll debug(){ rep(i,0,data.size()){ root(i); cout<>n>>q; WeightedUnionFind uf(n); vectorv(n); auto f=[&](ll x){ return v[uf.root(x)]+uf.weight(x); }; while(q--){ ll t,a,b;cin>>t>>a>>b;a--; if(t==1){ b--; if(uf.find(a,b))continue; else{ uf.unite(a,b,f(b)-f(a)); } } if(t==2){ v[uf.root(a)]+=b; } if(t==3){ cout<