As a Review.

Typora even cannot deal with $\LaTeX$ in sudo mode?

Des.

Giving a undirected graph of $N$ nodes and $M$ edges. And you are given $Q$ operations, they might be deleting an edge or ask if there’re at least 2 paths without intersection between 2 nodes.

Sol.

The situation in description is exactly what a biconnected-component of a graph is, as what we called BCC.

However deleting operation is difficult to execute, so we reverse the operation sequence and answer questions off-line.

When edges on the tree form a loop, a BCC is generated, and we shrink all nodes on that loop into a specific node, this can be maintained with a UFS.

When answering, just check if the two nodes are in the same component.

Notice that as we shrink nodes, operation with $f[x]$ in LCT should be modified to $bel[f[i]]$, which is the representing node of one component.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef gp_hash_table<int, int>::iterator iter;

const int maxn = 1e+5 + 5;
const bool ANSWER_YES = true;
const bool ANSWER_NO = false;

struct querys {
int typ, u, v;
}q[maxn];

inline int rd() {
register int x = 0, c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
return x;
}
int n, m, Q, ans[maxn];
gp_hash_table<int, int> e_to_id[maxn];
int rev[maxn], ch[maxn][2], f[maxn], bel[maxn], fa[maxn];

int belong(int x) {
return bel[x] == x ? x : bel[x] = belong(bel[x]);
}
int find(int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
inline int getid(int x) {
return ch[belong(f[x])][1] == x;
}
inline int isroot(int x) {
return ch[belong(f[x])][0] != x && ch[belong(f[x])][1] != x;
}
inline void pushdown(int x) {
if (rev[x]) {
rev[ch[x][0]] ^= 1;
rev[ch[x][1]] ^= 1;
swap(ch[x][0], ch[x][1]);
rev[x] = 0;
}
}
inline void pushpath(int x) {
if (!isroot(x)) pushpath(belong(f[x]));
pushdown(x);
}
inline void rotate(int x) {
int y = belong(f[x]), z = belong(f[y]), k = getid(x);
if (!isroot(y))
ch[z][ch[z][1] == y] = x;
ch[y][k] = ch[x][k ^ 1];
ch[x][k ^ 1] = y;
f[y] = x; f[ch[y][k]] = y; f[x] = z;
}
inline void splay(int x) {
pushpath(x);
for (; !isroot(x); rotate(x)) {
int y = belong(f[x]);
if (!isroot(y))
rotate(getid(y) == getid(x) ? y : x);
}
}
inline void access(int x) {
for (int y = 0; x; y = x, x = belong(f[x]))
splay(x), ch[x][1] = y;
}
inline void makeroot(int x) {
access(x); splay(x); rev[x] ^= 1;
}
inline void split(int x, int y) {
makeroot(x); access(y); splay(y);
}
inline void link(int x, int y) {
makeroot(x); f[x] = y;
}
void merge(int x, int y) {
bel[belong(x)] = y; pushdown(x);
if (ch[x][0]) merge(ch[x][0], y);
ch[x][0] = 0;
if (ch[x][1]) merge(ch[x][1], y);
ch[x][1] = 0;
}
inline void add(int x, int y) {
x = belong(x); y = belong(y);
if (x == y) return;
int fx = find(x), fy = find(y);
if (fx != fy) {
fa[fx] = fy;
link(x, y);
} else {
split(x, y);
merge(y, y);
}
}
inline bool query(int x, int y) {
x = belong(x); y = belong(y);
if (x == y) return ANSWER_YES;
else return ANSWER_NO;
}

int main() {
n = rd(); m = rd(); Q = rd();
int u, v;
for (int i = 1; i <= n; ++i)
fa[i] = bel[i] = i;
for (int i = 1; i <= m; ++i) {
u = rd();
v = rd();
int mn = min(u, v), mx = max(u, v);
e_to_id[mn][mx] = i;
}
char opt[5];
for (int i = 1; i <= Q; ++i) {
scanf("%s", opt);
if (opt[0] == 'Z') {
q[i].typ = 0;
q[i].u = rd(); q[i].v = rd();
int mn = min(q[i].u, q[i].v), mx = max(q[i].u, q[i].v);
e_to_id[mn][mx] = 0;
} else {
q[i].typ = 1;
q[i].u = rd(); q[i].v = rd();
}
}
for (int i = 1; i <= n; ++i) {
for (iter p = e_to_id[i].begin(); p != e_to_id[i].end(); ++p) {
if (p->second == 0) continue;
else add(i, p->first);//, printf("%d %d\n", i, p.first);
}
}
for (int i = Q; i; --i) {
if (q[i].typ == 0) {
add(q[i].u, q[i].v);
} else {
ans[i] = query(q[i].u, q[i].v);
}
}
for (int i = 1; i <= Q; ++i)
if (q[i].typ)
puts(ans[i] ? "Yes" : "No");
}