I’ve checked for various values and the code seems to be running fine but it not getting submitted on hackerblocks and only passes one test case.
My code gives the right answer but not getting submitted
@amanb25 your code will see overflow for large value of vertices (long long will also not help), think this way-> if you have x cities interconnected, then you may choose one of the city from these x cities and other from remaining n-x, hence contribution is x*(n-x).
Do this for every component, this will avoid overflow!
I’ve edited the code and changed the calculate function, however still it is not being submitted on hackerblocks. I think it is still not able to handle really larder values
Hello @amanb25 this code can be easilt implemented by DSU(disjoint set union) ,try to implement and think that way.
this question becomes very simple by DSU.
Happy Learning !!
Yes, I’ve implemented that and it worked but the video said to also try dfs approach, so I wanted to know where I’ m going wrong.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.