-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path19_October.cpp
More file actions
35 lines (35 loc) · 793 Bytes
/
19_October.cpp
File metadata and controls
35 lines (35 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution
{
bool *visited;
vector<int>*adj;
public:
bool dfs(int src,int inPath,int v)
{
visited[src]=true;
if(inPath==v)
return true;
for(auto it:adj[src])
{
if(!visited[it]&&dfs(it,inPath+1,v))
return true;
}
visited[src]=false;
return false;
}
bool check(int N,int M,vector<vector<int>> E)
{
// code here
visited=new bool[N+1];
adj=new vector<int>[N+1];
for(int i=0;i<M;i++)
{
adj[E[i][0]].push_back(E[i][1]),adj[E[i][1]].push_back(E[i][0]);
}
for(int i=1;i<=N;i++)
visited[i]=false;
for(int i=1;i<=N;i++)
if(dfs(i,1,N))
return true;
return false;
}
};