Edge query, point to update the template title.
#include <iostream>#include<cstdio>#include<cstring>#include<map>#include<vector>#include<stdlib.h>using namespaceStd;typedefLong LongLL;Const intMAXN =222222;structnode{intto;intNext;} E[MAXN*2];#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1intHEAD[MAXN];intSON[MAXN];intTOP[MAXN];intFATHER[MAXN];intDEEP[MAXN];intLenintZ;intSIZE[MAXN];intPOS[MAXN];intsum[maxn<<2];voidAddint from,intTo ) {e[len].to=to ; E[len].next= head[ from]; head[ from] = len++;}intedge[maxn][Ten];voidInitintx) {Son[x]=0; SIZE[X] =1; for(inti = head[x]; I! =-1; i =E[i].next) { intCC =e[i].to; if(CC = = Father[x])Continue; DEEP[CC]= Deep[x] +1; FATHER[CC] =x; Init (CC); SIZE[X]+=SIZE[CC]; if(Size[son[x]] < SIZE[CC]) son[x] =cc; }}voidDfsintXintTP) {Pos[x]= ++z;top[x] =TP; if(Son[x]) DFS (SON[X], TP); for(inti = head[x]; I! =-1; i =E[i].next) { intCC =e[i].to; if(CC = = Father[x] | | cc = = son[x])Continue; DFS (CC, CC); }}voidUpintRT) {Sum[rt]= Sum[rt <<1] + sum[rt <<1|1];}voidUpdateintKeyintAnsintLintRintRT) { if(L = =R) {Sum[rt]= ans;return; } intMid = (L + r) >>1; if(Key <=mid) Update (key, ans, lson); Elseupdate (key, ans, rson); Up (RT);}intAskintLintRintLintRintRT) { if(L <= l&&r <= R)returnSum[rt]; intMid = (L + r) >>1; intAns =0; if(L <= mid) ans + =Ask (L, R, Lson); if(R > mid) ans + =Ask (L, R, Rson); returnans;}intGaointXinty) { intAns =0; intFX = top[x];intFY =Top[y]; while(FX! =FY) { if(Deep[fx] <Deep[fy]) {Swap (FX, FY); swap (x, y); } ans+ = Ask (Pos[fx], pos[x],1Z1); X= Father[fx]; FX =Top[x]; } if(x = = y)returnans; if(deep[x]>Deep[y]) swap (x, y); Ans+ = Ask (Pos[x] +1, Pos[y],1Z1); returnans;}intMain () {intn,q,s; intA,b,c; while(CIN >> N >> q >>s) {memset (sum,0,sizeof(sum)); Len=0; z =0; memset (Head,-1,sizeof(head)); Deep[s]=1 ; for(inti =1; I < n; i++) {scanf ("%d%d%d", &edge[i][0], &edge[i][1], &edge[i][2]); Add (edge[i][0], edge[i][1]); Add (edge[i][1], edge[i][0]); } init (1); Dfs1,1); for(inti =1; I < n; i++){ intA = edge[i][0];intb = edge[i][1];intc = edge[i][2]; if(Deep[a]>deep[b]) swap (edge[i][0], edge[i][1]); Update (pos[edge[i][1], C,1Z1); } while(q--) {scanf ("%d", &a); if(A = =0) {scanf ("%d", &b); intt =Gao (b, s); cout<< T <<Endl; S=b; } Else{scanf ("%d%d", &b, &c); edge[b][2] =C; Update (pos[edge[b][1], C,1Z1); } } } return 0;}
Poj2763housewife Wind tree chain split