eolymp
bolt
Try our new interface for solving problems
Problems

Cut a graph

Cut a graph

The undirected graph is given. Two types of operations are performed on graph in the given order: \begin{itemize} \item \textbf{cut} --- cut a graph, or delete an edge from a graph; \item \textbf{ask} --- check, whether two given vertices lie in the same connected component. \end{itemize} It is known that after performing all types of \textbf{cut} operations there is no edges left in the graph. Give the result for each \textbf{ask} operation. \InputFile The first line contains three integers --- the number of vertices $n$ in a graph, the number of edges $m$ and the number of operations $k~ (1 \le n \le 50000, 0 \le m \le 10^5, m \le k ≤ 150000)$. The next $m$ lines define the graph edges; $i$-th line contains two integers $u_i$ and $v_i~(1 \le u_i, v_i \le n)$ --- the end numbers of the $i$-th edge. The vertices are numbered starting from one; graph does not contain multiple edges and loops. The next $k$ lines describe the operations. Operation of type \textbf{cut} is given with the line "\textbf{cut u v}" $~(1 \le u, v \le n)$, which means that the edge between the vertices $u$ and $v$ is deleted from a graph. Operation of type \textbf{ask} is given with the line "\textbf{ask u v}" $~(1 \le u, v \le n)$, which means that you need to know are the vertices $u$ and $v$ in the same connected component. It is guaranteed that each edge of the graph meets in \textbf{cut} operations exactly once. \OutputFile For each \textbf{ask} operation print in a separate line the word "\textbf{YES}", if two given vertices are in the same connected component, and "\textbf{NO}" otherwise. The order of answers must match the order of \textbf{ask} operations in input data.
Time limit 3 seconds
Memory limit 128 MiB
Input example #1
3 3 7
1 2
2 3
3 1
ask 3 3
cut 1 2
ask 1 2
cut 1 3
ask 2 1
cut 2 3
ask 3 1
Output example #1
YES
YES
NO
NO