Very easy solution using DFS


#1

vector dp[100001];
vector check(100001);

void dfs(int v)
{
check[v] = 1;

for(auto x: dp[v])
{
    if(check[x]==0)
    {
        dfs(x);
    }
}

}

int Solution::solve(int A, vector<vector > &B)
{

for(int x=1; x<=A; x++)
{
    dp[x].clear();
}

for(int x=0; x<B.size(); x++)
{
    dp[B[x][0]].push_back(B[x][1]);
  //  dp[B[x][1]].push_back(B[x][0]);
}

for(int x=1; x<=A; x++)
{
    check[x] = 0;
}

dfs(1);

return check[A];

}


#2

int Solution::solve(int A, vector<vector > &B)
{
vector<vector>v(A) ;

if(A == 1)
return 1 ;

for(int i=0; i<B.size(); i++)
{
    int from = B[i][0] ;
    int to = B[i][1] ;
    
    --from ;
    --to ;
    
    v[from].push_back(to) ;
}

queue<int>q ;
vector<bool>vis(A, false) ;

vis[0] = true ;

vector<int>temp = v[0] ;

for(int i=0; i<temp.size(); i++)
{
    q.push(temp[i]) ;
    vis[temp[i]] = true ;
}

while(!q.empty())
{
    int from = q.front() ;
    
    if(from == A-1)
    return 1 ;
    
    q.pop() ;
    
    vector<int>temp = v[from] ;
    
    for(int i=0; i<temp.size(); i++)
    {
        if(vis[temp[i]] == false)
        {
            q.push(temp[i]) ;
            vis[temp[i]] = true ;
        }
    }
}

return 0 ;

}