In the middle of each side two points and a virtual point to represent this edge right, you can take the edge of the right to point.
To use the LCT to maintain a spanning tree with a bridge on the edge of the tree.
For a non-tree edge, the weights on all sides of the corresponding path on the tree are modified to 0, indicating that they are not bridges.
Then the query is processed backwards, for each deleted edge, the two-point path top right is modified to 0.
Inquiry is equivalent to querying the two-point edge and, if two points are connected and the path does not exist on the bridge, there is a solution.
#include <cstdio> #include <map>const int N=200010,buf=5000000;char buf[buf],*buf=buf;int A[N],N,M,I,X,FA [N],edge[n][2],ask[n][4],q;struct lct{int f,son[2],sum,data;bool Rev,tag;} T[n];int father (int x) {return fa[x]==x?x:fa[x]=father (fa[x]);} std::map<int,bool>del[n>>1];inline void Swap (int&a,int&b) {int c=a;a=b;b=c;} inline bool IsRoot (int x) {return! t[x].f| | T[t[x].f].son[0]!=x&&t[t[x].f].son[1]!=x;} inline void Rev1 (int x) {if (!x) Return;swap (t[x].son[0],t[x].son[1]), t[x].rev^=1;} inline void Makezero1 (int x) {if (!x) return; t[x].sum=t[x].data=0; T[x].tag=1;} inline void pb (int x) {if (T[x].rev) Rev1 (t[x].son[0]), Rev1 (T[x].son[1]), t[x].rev=0; if (T[x].tag) Makezero1 (t[x].son[0]), Makezero1 (T[x].son[1]), t[x].tag=0;} inline void up (int x) {t[x].sum=t[x].data| t[t[x].son[0]].sum| T[t[x].son[1]].sum;} inline void rotate (int x) {int y=t[x].f,w=t[y].son[1]==x; T[Y].SON[W]=T[X].SON[W^1]; if (t[x].son[w^1]) t[t[x].son[w^1]].f=y; if (T[Y].F) {int z=t[y].f; if (t[z].son[0]==y) T[z].son[0]=x;else if (t[z].son[1]==y) t[z].son[1]=x; } t[x].f=t[y].f; T[x].son[w^1]=y; T[y].f=x;up (y);} inline void splay (int x) {int s=1,i=x,y;a[1]=i; while (!isroot (i)) a[++s]=i=t[i].f; while (s) PB (a[s--]); while (!isroot (x)) {y=t[x].f; if (!isroot (y)) {if ((t[t[y].f].son[0]==y) ^ (t[y].son[0]==x)) rotate (x); else rotate (y);} Rotate (x); } up (x);} inline void access (int x) {for (int y=0;x;y=x,x=t[x].f) splay (x), T[x].son[1]=y,up (x);} inline void makeroot (int x) {access (x); splay (x); Rev1 (x);} inline void link (int x,int y) {makeroot (x); T[x].f=y;access (x);} inline void Makezero (int x,int y) {if (father (x)!=father (y)) {fa[father (x)]=father (y); n++; T[n].sum=t[n].data=1; Link (x,n); link (n,y); Return } makeroot (x); Access (y); Splay (x); Makezero1 (x);} inline int getsum (int x,int y) {if (father (x)!=father (y)) return 1; Makeroot (x); Access (y); Splay (x); return t[x].sum;} inline void Read (Int&a) {for (a=0;*buf<48;buf++), while (*buf>47) a=a*10+*buf++-48;} int main () {fread(Buf,1,buf,stdin); Read (n); read (m); Read (q); for (i=1;i<=n;i++) fa[i]=i; for (i=1;i<=m;i++) {read (edge[i][0]); Read (edge[i][1]); if (edge[i][0]>edge[i][1]) swap (edge[i][0],edge[i][1]); } for (i=1;i<=q;i++) {while (*buf!= ' Z ' &&*buf!= ' P ') buf++; ask[i][0]=x=*buf== ' P ', buf++; Read (ask[i][1]); Read (ask[i][2]); if (ask[i][1]>ask[i][2]) swap (ask[i][1],ask[i][2]); if (!x) del[ask[i][1]][ask[i][2]]=1; } for (i=1;i<=m;i++) if (!del[edge[i][0]][edge[i][1]) if (father (Edge[i][0])!=father (edge[i][1])) {Fa[father (Edge I [0]] =father (edge[i][1]); n++; T[n].sum=t[n].data=1; Link (edge[i][0],n); link (n,edge[i][1]); Del[edge[i][0]][edge[i][1]]=1; } for (i=1;i<=m;i++) if (!del[edge[i][0]][edge[i][1]]) Makezero (edge[i][0],edge[i][1]); for (i=q;i;i--) if (!ask[i][0]) Makezero (ask[i][1],ask[i][2]); else Ask[i][3]=getsum (ask[i][1],ask[i][2]); for (i=1;i<=q;i++) if (ask[i][0]) puts (ask[i][3]? " NIE ":" TAK "); return 0;}
BZOJ3069: [Pa2011]hard Choice difficult choice