Simple c++ sol 121 21212

interview-questions
programming
Tags: #<Tag:0x00007f2428d42d78> #<Tag:0x00007f2428d42c38>

#1

vectorvis;
vector<vector>adj;
bool dfs(int x,int ans)
{ vis[x]=1;
if(x==ans)
return true;
for(auto k:adj[x])
{
if(!vis[k])
{
if(dfs(k,ans))
return true;
}
}
return false;
}
int Solution::solve(int a, vector<vector > &b) {
int i;
vis=vector(a+1,0);
adj=vector<vector>(a+1);

for(i=0;i<b.size();i++)
{
    adj[b[i][0]].push_back(b[i][1]);
            
}
return dfs(1,a);

}