#include #include using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second typedef long long ll; typedef vector vec; typedef vector mat; ll N,M,H,W,Q,K,A,B; string S; const ll MOD = 998244353; //const ll MOD = (1e+9) + 7; typedef pair P; const ll INF = (1LL<<60); int main() { cin>>N>>Q; class union_find{ ll nn; vector parent, tree_size, when_parent; vector> v_lib; public: union_find(unsigned long _n) : parent(_n), tree_size(_n, 1),when_parent(_n, -1), v_lib(_n, vector

(1, P(-1,0))), nn(_n){ for(unsigned long i = 0; i < _n; ++i)parent[i] = i; } ll find(ll x){ while(parent[x] != x)x = parent[x]; return x; } ll score(ll x, ll id){ ll score = v_lib[x][v_lib[x].size() - 1].se; //cout<se<se; } return score; } void add(ll x, ll b, ll id){ x = find(x); v_lib[x].emplace_back(id, b + v_lib[x][v_lib[x].size() - 1].se); } void merge(ll a, ll b, ll id){ a = find(a); b = find(b); if(a==b) return; if(tree_size[a] < tree_size[b])swap(a, b); tree_size[a] += tree_size[b]; parent[b] = a; when_parent[b] = id; } }; union_find uf(N + 1); rep(i,Q){ int a, b, c; scanf("%d%d%d", &a, &b, &c); if(a == 1){ uf.merge(b, c, i); }else if(a == 2){ uf.add(b, c, i); }else{ printf("%lld\n", uf.score(b, i)); } } }