#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #pragma warning(disable:4996) typedef long long ll; typedef unsigned long long ull; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define INF 2140000000 //const long long MOD = 1000000007; const long long MOD = 998244353; using namespace std; class UF { private: int num; vector par; vector siz; vector wt; // diff from par public: vector parval; // val of root public: UF(int n): num(n) { par.resize(n); siz.resize(n); wt.resize(n); parval.resize(n); int i; for(i=0; i t(Q), a(Q), b(Q); UF uf(n); int i; for (i = 0; i < Q; i++) { scanf("%d%d%d", &t[i], &a[i], &b[i]); a[i]--; if(t[i]==1) b[i]--; if (t[i] == 1) { if (uf.same(a[i], b[i])) { continue; } int pa = uf.find(a[i]); ll vala = uf.parval[pa] + uf.GetWt(a[i]); int pb = uf.find(b[i]); ll valb = uf.parval[pb] + uf.GetWt(b[i]); uf.unite(a[i], b[i], valb - vala); } else if (t[i] == 2) { int pa = uf.find(a[i]); uf.parval[pa] += b[i]; } else { int pa = uf.find(a[i]); ll vala = uf.parval[pa] + uf.GetWt(a[i]); printf("%lld\n", vala); } } return; } int main(int argc, char* argv[]) { #if 1 solve(); #else int T; scanf("%d", &T); int t; for(t=0; t