Help DSU question?

the question is very clear and look easy but not getting to solve this , tried with floyed warshal algorithm but number of edges are n<=10^5 , so it’s TLE
any body can help with this : - LeetCode

1 Like

If you know its a standard DSU question, why not apply union find and then check where the problem arises, if any.