You are given the ‘Edges’ = [[0,1], [1, 2], [1, 4], [2, 3], [3, 0], [3, 1], [4, 3]], describing the following graph:
Here you can have the path, [0 -> 1 -> 2 -> 3 -> 1 -> 4 -> 3 -> 0], which is using every edge of the graph. Hence the graph is Eulerian and the answer is True.
The first line of input contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains two space-separated integers, ‘N’ and ‘M’, representing the number of nodes and edges in the given graph, respectively.
The following M lines of each test case contains two space-separated integers, Edges[i][0] and Edges[i][1] representing an directed edge in the graph from ‘Edges[i][0]’ to ‘Edges[i][1]’
For each test case, print ‘True’ if the given graph is eulerian, else print 'False'.
Print a separate line for each test case.
1 ≤ T ≤10
1 ≤ N, M ≤ 10^3
1 ≤ Edges[i][0], Edges[i][1] < N
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the given function.
In this approach, we can see that for the graph to be Eulerian,
If the above two conditions are met, the graph will contain an eulerian circuit and thus will be an eulerian graph.
We will use the Kosaraju algorithm to find if the graph has a single strongly connected component and then calculate the indegree and outdegree of each node.
We create a kosarajuAlorithm(adjList, n) function to get the strongly connected components of the graph, where ‘adjList’ is the adjacency list of the graph and n is the number of nodes.
Kosaraju algorithm needs a few more utility functions of the graph:
Find Center of Star Graph
Critical Connections in a Network
Critical Connections in a Network
Critical Connections in a Network
Critical Connections in a Network
COUNT ISLANDS
Distance to a Cycle in Undirected Graph
Tomato Timer
Tomato Timer