Problem in BFS(IARCS GREATESC)

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.

Try replacing memset(visited,false,1000001) with a for loop. I have faced similar problem earlier and figured out that memset was the culprit.The code seems to be correct.
Read this for more info: Memset gives WA!! Ciel and Tomya.
Is it safe to memset bool to 0? and sizeof(bool) might be useful.

I tried doing that but still the WA persists. :frowning:
Thanks btw

//