DISHOWN - Editorial

Can anyone please explain why am i getting WA?
https://www.codechef.com/viewsolution/33884752

Please can anyone help me figure out the mistake in the code.
Thanks in advance.
https://www.codechef.com/viewsolution/38086782

I was getting TLE, Could not figure out the reason. I have even applied path Compression and union by rank. I am attaching my code please do help me out with this.

https://www.codechef.com/viewsolution/48776191

Thank you in advance