Want to solve this problem? Login now to get access to solve the problems

Problem

Submissions

Solution

Leaderboard

Coming soon

2

Difficulty: MEDIUM

Avg. time to solve

32 min

Success Rate

65%

Problem Statement

Suggest Edit

```
There are no self-loops(an edge connecting the vertice to itself) in the given graph.
```

```
The first line of input will contain three integers V, E, and S, separated by a single space.
From the second line onwards, the next 'E' lines will denote the edge of the graphs.
Every edge is defined by two single space-separated integers 'a' and 'b', which signifies an edge between vertice 'a' and vertice 'b'.
```

```
The single line contains an string, "True" if cycle exists, else "False".
```

```
1 <= V <= 10^5
0 <= E <= 2 * 10^5
0 <= u,v < V
Time Limit: 1sec
```

```
4 4
0 1
1 2
2 3
3 0
```

```
True
```

```
From node 0 we can reach 0 again by following this sequence of nodes in the path: 0,1,2,3,0.
Similarly from any of the node we can reach again to that node by following a path. The graph in itself is a cycle.
```

```
5 3
0 1
1 2
3 4
```

```
False
```

Want to solve this problem? Login now to get access to solve the problems