Is there O(N^2) solution possible for TREEDISTSET?

for the problem TREEDISTSET, the number of vertices is n.
and n <= 1000, which I was taking as a hint for N^2 solution.
I have gone through the solution which is O(N).
I want to know if there’s any O(N^2) solution possible without Diameter observation.
if yes can anyone share?
as N <= 1000, I was thinking of N^2 solutions the whole time.

Thanks in advance.

U also need to consider T, when checking for complexity

Please also check that it is clearly mentioned that “Sum of N over ALL test cases doesnt exceed 2000”

1 Like