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:https://codeforces.com/contest/893/submission/88430254
Question Link:https://codeforces.com/contest/893/problem/C:
tutorial:https://codeforces.com/blog/entry/55989

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) : “https://codeforces.com/contest/893/submission/88434469

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

  1. AC solution : “https://codeforces.com/contest/893/submission/88434769
1 Like

Ya bro I missed it. :grinning: