For this Question: Given an undirected graph, the task is to detect if there is a cycle in the undirected graph or not.The first line of input contains two integers N and M which denotes the no of vertices and no of edges in the graph respectively. 
Next M lines contain space-separated integers u and v denoting that there is a directed edge from u to v.

Constraints:
1 <= N, M <= 1000
0 <= u, v <=  N-1, u != v
There are no self loops or multiple edges.
Print 'Yes' if there is a cycle in the graph otherwise print 'No'Sample Input 1:
4 5
0 1
1 2
2 3
3 0
0 2

Sample Output 1:
Yes

Explanation:
There is a cycle with nodes 0, 1, 2, 3

Sample Input 2:
4 3
0 1
1 2
2 3

Sample Output 2:
No

Explanation:
There is no cycle in this graph, I have written this Solution Code: 
def dfs(adjList,vis,start,prev):
    vis[start]=True
    for i in adjList[start]:
        if i == prev:
            continue
        if vis[i]:
            return True
        else:
            dfs(adjList,vis,i,start)
    return False 

np=list(map(int,input().rstrip().split()))
n=np[0]
e=np[1]
adjList = [[] for i in range(n+1)]
for i in range(e):
    edge = list(map(int,input().rstrip().split()))
    adjList[edge[0]].append(edge[1])
    adjList[edge[1]].append(edge[0])

vis = [False for i in range(n+1)]
flag=0

for i in range(n):
    if not vis[i]:
        if dfs(adjList,vis,i,0):
            flag=1
            break
if flag:
    print("Yes")
else:
    print("No"), In this Programming Language: Python, Now tell me if this Code is compilable or not?