Detect whether there is a cycle in an undirected graph using Depth First Search (DFS).
{
"V": 5,
"adj": [
[
1
],
[
0,
2,
4
],
[
1,
3
],
[
2,
4
],
[
1,
3
]
]
}true{
"V": 4,
"adj": [
[],
[
2
],
[
1,
3
],
[
2
]
]
}false{
"V": 3,
"adj": [
[
1,
2
],
[
0,
2
],
[
0,
1
]
]
}trueSign in to Run Code and Submit