how to improve solution of july long problem GEARS

graph
july18
union-find

#1

my solution is giving TLE for subtask 2 because for every type 3 query i am checking component is bipartite or not using DFS.i used weighted union-find with path compression but using only that for checking x & y connected or not. so, how to modify my solution so, i have not to perform whole bipartite check of component again-again for type 3 query.
link to solution


#2

Refer link text
Understand it and then try to implement on your own.


#3

Once a set is blocked, it will always be block. Make an array and mark the set-element’th index as blocked for such arrangement. Then, use find_parent+Path compression to check quickly.