Https://hack.codingblocks.com/contests/c/537/1276

https://hack.codingblocks.com/contests/c/537/1276

according to the code in a video, the if don’t the = sign then it is showing the wrong answer
the code of that portion is :-
for(int u=0;u<=n(HERE);u++){
for(int dice=1;dice<=6;dice++){
int v = u+dice+board[u+dice];
g.addEdge(u,v);
}
}

my code link is:-
https://ide.codingblocks.com/s/47094

Hey Sanyam, you are getting the right answer with this code and all the test case are passing. So, I am unable to get your doubt can you please elaborate, what are you trying to ask.

Sir please run this and check that the output of the code is 0

Yes I have run your code and its working if you are using for(int u=0;u<=n;u++) this for loop till n. I’m not able to understand what you are trying to ask.

Yes sir that’s my doubt, why do we need to run the loop upto n since we don’t want to go anywhere from there(destination)

Hey Sanyam, problem is not with the for loop, actually when you are calling g.bfs(), you are supposed to pass source and destination, and in this source is 0 and destination is n-1 as the array is from 0 to n-1. So, write the function call like this g.bfs(0,n-1) pass the destination as n-1 instead of n.

Sir, I am little confused now , as you said that the array is upto n-1 and destination is also n-1 then how it is correct , as according to the question the destination is n not n-1

Hey Sanyam, this is because in arrays we store elements from 0 to n-1 not from 1 to n. If we say we are storing n elements in an array that means we are storing n elements starting from 0th element to (n-1)th index. Therefore, destination will be at (n-1)th index which is actually nth element of the array.