This is a problem LCT board, saying that white is on the LCT support segment tree 2 operation.
So I just wanted to keep a board, and what does not speak (I will not say, can only be fraught 2333).
However, the code notes for reference.
Code
#include<bits/stdc++.h> using namespace std; typedef unsigned int uint; const int N=1e5+5; const uint mod=51061; inline int read(){ int x=0,w=0;char ch=0; while(!isdigit(ch)) w|=ch=='-',ch=getchar(); while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar (); return W -? X: X; } int F [N], SZ [N], C [N] [ 2 ]; uint V [N], S [N], ml [N], AD [ N]; // int will burst BOOL RV [N]; #define LC C [X] [0] #define RC C [X] [. 1] #define MUL (X) * X = Val, X% = MOD #define the Add (X) = X + Val, X% = MOD // I used the root wording is determined Not inline BOOL NRT ( int X) { return C [F [X]] [ 0 ] == X || C [F [X]] [ . 1 ] == X;}; void a pushup ( int X) { S [X]= (S [LC] + S [RC] + V [X])% MOD; SZ [X] = SZ [LC] + SZ [RC] + . 1 ; } // custom priority: multiplication> addition> flip void Rev ( int X) {LC ^ = RC ^ = LC ^ = RC; RV [X] ^ = . 1 ;}; void adder Mul ( int X, uint Val) {MUL (V [X]), MUL (S [X]), MUL (ml [X]), MUL (AD [X]);} void the Add ( int X, uint Val) {the Add (V [X]); the Add (AD [X]); Val * = SZ [X]; Val% = MOD; the Add (S [X]);} void pushdown ( int X) { IF (ml [X] ^ . 1 ) adder Mul (LC, ml [X]), adder Mul (RC, ml [X]), ml [X] = . 1 ; IF(AD [X]) the Add (LC, AD [X]), the Add (RC, AD [X]), AD [X] = 0 ; IF (RV [X]) Rev (LC), Rev (RC), RV [X] = 0 ; } // less with conventional LCT no two int GET ( int X) { return X == C [F [X]] [ . 1 ];} void Link ( int X, int Y, int D) {C [X] [D] = Y; F [Y] = X;} void Rotate ( int X) { int Y = F [X], Z = F [Y], D = GET (X); IF (NRT (Y)) C [Z] [ GET (Y)] = X; F [X] = Z; //If y = rt, described y-> z is a virtual edge, i.e. x and z belong to two different Splay, even if such sides also z-> x, the consequences ...... emmm // but x-> z must be connected, because even if y is the root, after the spin-up x x to become the root, and (except for the root of the original tree Splay belongs) in a parent LCT Spaly root side must be a virtual edge, corresponding to x y even inherited the mission virtual edge. . . Link (Y, C [X] [D ^ . 1 ], D); Link (X, Y, D ^ . 1 ); a pushup (Y), a pushup (X); } int ST [N], TP; void The splay ( int X) { int T = X; // manually with a stack pushdown ST [TP = . 1 ] = T; the while (NRT (T)) ST [TP ++] = T = F [T]; the while (TP) pushdown (ST [tp-- ]); for(;nrt(x);rotate(x)){ int y=f[x]; if(nrt(y)) get(x)^get(y)?rotate(x):rotate(y); } } void access(int x){ for(int y=0;x;x=f[y=x]) splay(x),c[x][1]=y,pushup(x); } void makert(int x){ access(x),splay(x),Rev(x); } int findrt(int x){ access(x),splay(x); while(lc) pushdown(x),x=LC; The splay (X); return X; } void Split ( int X, int Y) { makert (X), Access (Y), The splay (Y); } void Link ( int X, int Y) { makert (X ); IF (findrt (Y) ^ X) F [X] = Y; } void cut ( int X, int Y) { makert (X); // in this question because of the legal guarantees operation should therefore be cut without judgment IF (findrt (Y) == X && F [Y] == X && C [Y] [! 0 F [Y] = C [X] []) . 1 ] = 0 , a pushup (X); } int n,m; int main(){ n=read(),m=read(); for(int i=1;i<=n;++i) v[i]=ml[i]=sz[i]=1; for(int i=1;i<n;++i) link(read(),read()); char op[2];int x,y; while(m--){ scanf("%s",op); x=read(),y=read(); switch(op[0]){ case '+':split(x,y);Add(y,read());break; case '-':cut(x,y);link(read(),read());break; case '*':split(x,y);Mul(y,read());break; case '/':split(x,y);cout<<s[y]<<endl;break; } } return 0; }