Codeforces EDU Disjoint set Practice problem 4

Please :pray: anybody tell me how to approach this particular problem

Store graph int a vector < set > graph[n+1]. Then take all query and save it. While taking query if you have to cut any edge u-v, then erase u from graph[v] and v from graph[u]. Now go through all graph[i] and do union with all its elements with i. After that reverse the saved query’s. Now we answer each query. If its “cut” type, we already cut it, so now we unite u and v. Else we check if their parent is same or not. For each query we store the ans. Finally print those answer from end to begin.

One of the comments from the Codeforces discussion. Hope it helps.