long long is not working …It fails on testcase 8.
Code is perfectly fine ,no issues with code logic and wrong approach ,just it not running for very big values .
I read the tutorial and found 64bit variable to store final answer.
also found a method like this
and taking min(arr[i] ,var)
//The question is a cakewalk just we need to to dfs including cas of disconnected graph .
Please help U can also see the tutorial .