#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; // constexpr int mod = 1000000007; constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } struct UnionFind{ int sz; vector par; vector rank; vector weight; vector lazy; vector> vs; UnionFind(int n) : sz(n) { par.resize(sz); rank.assign(sz, 0); weight.resize(sz); lazy.resize(sz); vs.resize(sz); for(int i = 0; i < sz; ++i){ par[i] = i; vs[i].emplace_back(i); } } int find(int x){ if(par[x] == x) return x; else return par[x] = find(par[x]); } bool same(int x, int y){ return find(x) == find(y); } bool unite(int x, int y){ x = find(x), y = find(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y); par[y] = x; for(int v : vs[y]){ weight[v] += lazy[y] - lazy[x]; vs[x].emplace_back(v); } vs[y].clear(); lazy[y] = 0; if(rank[x] == rank[y]) ++rank[x]; return true; } void update(int x, int y){ lazy[find(x)] += y; } int prod(int x){ return weight[x] + lazy[find(x)]; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q, T, A, B; cin >> N >> Q; UnionFind uf(N + 1); for(int q = 0; q < Q; ++q){ cin >> T >> A >> B; if(T == 1) uf.unite(A, B); else if(T == 2) uf.update(A, B); else cout << uf.prod(A) << '\n'; } return 0; }