Graph
Graph
Graph
8 10 0 0,1,6,4,2,3,5,7
0 1 0,1,2,5,6,3,4,7
0 2
0 5
1 6
2 3
2 4
3 4
4 5
4 6
5 7
8
0 5 3 0 0 11 0 0
5 0 5 0 0 0 7 11
3 5 0 11 1 7 0 0
0 0 11 0 11 0 11 0
0 0 1 11 0 1 5 7
11 0 7 0 1 0 0 42
0 7 0 11 5 0 0 42
0 11 0 0 7 42 42 0
The MST is shown as figure 4 and the weight of minimum spanning tree is 33:
The first line contains a positive integer N (1 ≤ N ≤ 100) which is the number of vertex of undirected
graph.
The next N line, each line containing N integers that represent the adjacency matrix.
The output: the results need to be saved to the mst_output.txt text file:
The output contains the weight of the minimum spanning tree and the edges.
[Graph]
Sample Input 1 Sample Output 1
8 Prime:
0 5 3 0 0 11 0 0 33
5 0 5 0 0 0 7 11 0 0 0
3 5 0 11 1 7 0 0 0 1 5
0 0 11 0 11 0 11 0 0 2 3
0 0 1 11 0 1 5 7 2 3 11
11 0 7 0 1 0 0 42 2 4 1
0 7 0 11 5 0 0 42 4 5 1
0 11 0 0 7 42 42 0 4 6 5
4 7 7
Kruskal:
33
2 4 1
4 5 1
0 2 3
0 1 5
4 6 5
4 7 7
2 3 11
5 0 0,2,1,4,3,1,0
0 1 1 0 0
1 0 1 1 1
1 1 0 0 0
0 1 0 0 1
[Graph]
0 1 0 1 0
10
0 1 1 1 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1 0 1
Figure 3. The undirected graph that created by giving adjacency matrix
0 0 0 0 0 0 0 0 1 0
The first line contains a positive integer N (1 ≤ N ≤ 100) which is the number of vertex of undirected
graph.
The next N line, each line containing N integers that represent the adjacency matrix.
The output: the results need to be saved to the cc_output.txt text file:
The first line contains number of connected components.
The next number of connected components line, each line contains the list of numbers representing
the DFS traversing of each connected component. Each number separated by one comma.
[Graph]
Sample Input 1 Sample Output 1
10 3
0 1 1 1 0 0 0 0 0 0 0,1,2,3,4
1 0 1 0 0 0 0 0 0 0 5,6
1 1 0 0 0 0 0 0 0 0 7,8,9
1 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1 0 1
0 0 0 0 0 0 0 0 1 0
The next N line, each line containing N integers that represent the adjacency matrix.
The output: the results need to be saved to the shortestPath_output.txt text file:
One line contains the shortest path from the starting vertex to the ending vertiex in the graph, each
number separated by one comma.
Cut vertex: 0
Cut vertex: 3
6 1
0 1 1 0 0 0
2 3
1 0 1 0 0 0
1 1 0 1 0 0
0 0 1 0 1 1
0 0 0 1 0 1
0 0 0 1 1 0