problem link—>
my solution code—>>
I used the dfs approach to solve the question but I guess have done some mistake plz help to correct it
problem link—>
my solution code—>>
I used the dfs approach to solve the question but I guess have done some mistake plz help to correct it
Hello @coderajay03 dry run your code for this line in dfs function:
return dis*dfs(neww,origin,dis1);
comment this line and see what error you are getting?
this line is producing the error.
Happy Learning!!
bhaiya in dry run my code is working as the way i want but don’t know why getting stackoverflow error !! I tried commenting that line too then program gave very partial answer I mean only corresponding nodes answer like A->B or B->C these answers correct but A->C that should be (A->B)x(A->C) is coming out wrong
my approach is very simple go in particular string’s map list and explore it’s nodes until the destination location is achieved i mean nomral dfs just multiply the weights in dfs bcz that’s how answer would be computed
Where you are performing dfs you have to make one visited array so that you can make check you are not visitig the same node again.
but you have not done like that and your code for that is being cinverted into infinite recursion.
Happy Learning!!
bhaiya i made corrections as u said some test cases still failing
https://ide.codingblocks.com/s/411847 check now updated as u said
bhaiya waiting for your response on this !!!
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.