#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 template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; class UnionFind { public: vector Parent; UnionFind(int N) { Parent = vector(N, -1); } int root(int A) { if (Parent[A] < 0) { return A; } return Parent[A] = root(Parent[A]); } long long size(int A) { return -(long long)Parent[root(A)]; } bool connect(int A, int B) { A = root(A); B = root(B); if (A == B) { return false; } /* if (size(A) < size(B)) { swap(A, B); } */ Parent[A] += Parent[B]; Parent[B] = A; return true; } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ int n, kkt; scanf("%d %d", &n, &kkt); vector pl(n); vector> v(n); for (int i = 0; i < n; i++) v[i].emplace_back(i); vector sc(n); UnionFind uni(n); while (kkt--) { int t, a, b; scanf("%d %d %d", &t, &a, &b); a--; if (t == 1) { b--; a = uni.root(a); b = uni.root(b); if (a == b) continue; if (uni.size(a) > uni.size(b)) swap(a, b); for (auto e : v[a]) sc[e] += pl[a] - pl[b]; for (auto e : v[a]) v[b].emplace_back(e); pl[a] = 0; v[a].clear(); uni.connect(b, a); } if (t == 2) { pl[uni.root(a)] += b; } if (t == 3) { printf("%d\n", sc[a] + pl[uni.root(a)]); } } return 0; }