Question 3:
Question 3: (3 marks)
Write a program to build an undirected graph by giving edge list.
A happy vertex is a vertex with positive degree; that is, a vertex that is an endpoint of at least one edge.
Your task is showing all happy vertices of the given graph in ascending format.
2
8
7
3
6
1
Figure 5. The undirected graph that created by giving edge list
All happy vertices of the matrix are 0, 1, 2, 3, 4, 5, 7.
The input: are stored in the happyVertices_input.txt text file:
The first line contains 2 positive integers N and M that separated by one space:
o N (1 ≤ N ≤20) is the number of vertex of undirected graph.
o M (N-1 ≤ M ≤190) is the number of edge of undirected graph.
The next M line, each line containing 2 positive integers u and v that separated by one space:
о u (0 ≤ u<N) the start vertex of the edge (u, v).
ov (0 ≤v<N, vu) the end vertex of the edge (u, v).
FUQae output: the results need to be saved to the happyVertices_output.txt text file: