I was solving some DSU question and i m not able to understand when should we do path compression and when not . For example like in these two questions .
Solution 1
Solution 2
For better idea of solution 2 visit
As you can see in 2nd question while finding cycle we are not doing path compression. If anyone can explain the concept behind this it would be very helpful.