Determine whether the graph is only composed of cycles and paths. Then determine the number of vertices in each cycle or path found.
— Salma Charad —
Graph Theory
Given a graph, The code checks if it has only cycles
and paths
as components, and if so, The following details are given:
First, we check if every vertex is of degree 1 or 2. If any other degree is encountered, the graph is rejected.
Finding the paths
:
Finding the cycles
:
enter number of vertices: 6
enter number of edges: 4
Enter edge: 1 2
Enter edge: 2 3
Enter edge: 4 5
Enter edge: 5 6
This graph has only paths and cycles as components.
The graph contains 2 Path(s) of size 3
enter number of vertices: 8
enter number of edges: 7
Enter edge: 1 2
Enter edge: 2 3
Enter edge: 3 4
Enter edge: 4 1
Enter edge: 5 6
Enter edge: 6 7
Enter edge: 7 8
This graph has only paths and cycles as components.
The graph contains 1 Path(s) of size 4
The graph contains 1 Cycle(s) of size 4