The Great Escape: Runtime Error

I tried solving the Great Escape on the INOI server: http://opc.iarcs.org.in/index.php/problems/GREATESC

I used a simple BFS to find the minimum number of jumps. But my code is showing segmentation fault in the last test case. Can anyone one point out my mistake?
My code:

#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
using namespace std;

vector<int> adjlist[3500];
queue<int> bfs;

int main()
{
    int n,m;
    cin >> n >> m;
    int a,b;
    while(m--)
    {
        cin >> a >> b;
        a--; b--;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    int s,t;
    cin >> s >> t;
    s--;
    t--;
    int v[n];
    memset(v,-1,sizeof(v));
    v[s] = 0;
    bfs.push(s);
    while(!bfs.empty())
    {
        int node = bfs.front();
        bfs.pop();
        int d = v[node];
        for(unsigned int i = 0;i < adjlist[node].size();i++)
        {
            int node2 = adjlist[node][i];
            if(v[node2] == -1)
            {
                v[node2] = d+1;
                bfs.push(node2);
            }
        }
    }
    if(v[t] == -1) cout << 0 << endl;
    else cout << v[t] << endl;
    return 0;
}
1 Like