Wrong Answer in GEARS

, ,

I have attempted the problem GEARS from this July Long Challenge. I maintained the graph in adjacency lists and used DSU to check if two vertices are connected. Whenever I connect two components, I changed the colors of the vertices in the smaller component, if the two vertices to be connected have the same color.
Please have a look at my code https://www.codechef.com/viewsolution/19290958 and tell me why does it give the wrong answer and why this algorithm is inefficient(it also gives TLE and NZEC).
Thank You.