Why am I getting TLE in my solution to a graph problem?

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

I used BFS on all nodes who haven’t been visited to find all connected components and their size. I see similar successful submissions to this question so why am I getting TLE?

vector<vector<int> > adj

Take this by reference instead of by value, as you have done with dist.

2 Likes

Thank you so much!

1 Like