Segmentation fault in 2-D vector

  adjacency-list, c++, graph, stl, vector
#include<bits/stdc++.h>
using namespace std;

int main(){

    int n,m;
    cin >> n>> m; 
    vector<vector<int>> adj( 1001 , vector<int> (1001, 0));
    for(int i=0;i<m;i++){
        int a,b;
        cin>> a>>b;
        adj[a][b]=1;
        adj[b][a]=1;
    }
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        if(adj[a][b]==1)
        cout <<"YES" <<endl;
        else
        cout << "NO" <<endl;
    }
}

The 2-D vector part is giving segmentation fault.Even though i assigned a size and value to vector elements
*

Source: Windows Questions C++

LEAVE A COMMENT