Codeforces :C. Rumor :Which variable should I use to store very big answer?

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
int var=INF;
and taking min(arr[i] ,var)

//The question is a cakewalk just we need to to dfs including cas of disconnected graph .

My submission:
Question Link:

Please help U can also see the tutorial .

Bro u did wrong , u just apply DFS from 1 , but its wrong we have to start dfs from that node whose value is smaller , as this leads to optimal results-

  1. My solution (same as u WA) : “

After this I just make pair of cost,current node and sort in ascending now I do BFS

  1. AC solution : “
1 Like

Ya bro I missed it. :grinning: