This is my BFS function which should return the shortest path from vertex s to vertex e.
Somehow my code gives WA in 1 test case on the judge. I am unable to debug the code and so here is my implementation of the BFS function. Please let me know the issue.
int BFS(int s, int e)
{
queue<int> q;
q.push(s);
bool visited[1000001];
memset(visited, false, 1000001);
int temp;
int d[V+1];
REP(i, V+1)
{
d[i]=-1;
}
d[0]=0;
d[s]=0;
while(!q.empty())
{
temp=q.front();
q.pop();
if(!visited[temp])
{
visited[temp]=true;
REP(i, graph[temp].size())
{
if(d[graph[temp][i]]==-1) d[graph[temp][i]] = d[temp]+1;
q.push(graph[temp][i]);
}
}
}
return (d[e]!=-1)?d[e]:0;
}
Thanks.