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:Submission #88430254 - Codeforces
Question Link:Problem - C - Codeforces
tutorial:Educational Codeforces Round 33 Editorial - Codeforces

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) : “Submission #88434469 - Codeforces

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

  1. AC solution : “Submission #88434769 - Codeforces
1 Like

Ya bro I missed it. :grinning: