problem link
my code
plz tell why this code is not getting submit and correct the code as well…along with explaination…
plz reply to this doubt as soon as possible…
Jack goes to rapture
Plz reply at least to this doubt
Are you solving it usinng Kruskal algorithm ? Coz that has the cleanest implementtation for this kind of problems, you just have to construct the MST and find the max of the path between the two nodes queried.
But we have to subtract the values as well…how will we implement that portion…
If we just do kruskal and get dist from 1 to gnodes then that will give wrong answer …
In ques we don’t just have to find dist …we have to find it in a modified manner (given in ques)…
I have tried to use Dijkstra here to find distance bw 1 and gnode but that also gives wrong ans …on submission…plz reply along with code
plz explain your approach as well…
@S19LPPP0202 thats why i am saying refer to the editorial and discussion in the hackerrrank problem coz it’s very tough problem and not easy to understand
since u have written this code yourself u should be able to explain it as well…
i have read the editorial you plz explain how have you written the code…reply at the earliest
@S19LPPP0202 if you have read then you would know the code is from editorial only thats why i am saying refer to the editorial
i havent understood the editorial i have just read it…that is why i am asking it as a doubt…
if i had understood the editorial why would i have raised a doubt…
you plz explain the soln to me …since u should have understood it
@S19LPPP0202 here
logic used :
used kruskal’s algorithm to find minimum fare that the weight of edge after
which node 1 and node N are connected for fast implementation use union
find data structure with weighting and path compression below is the the
which passes all testcase(and probably faster than editorial) .
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.