Data structure experiment Graph Theory 1: breadth-first search traversal based on the adjacent matrix
Data structure experiment Graph Theory 1: breadth-first search traversal based on the adjacent matrix Time Limit: 1000 ms Memory limit: 65536 K any questions? Click Here ^_^ The topic description gives a undirected connected graph with vertex numbers ranging from 0 to n-1. it traverses through the breadth-first search (BFS) and outputs The traversal Sequence starting from a certain vertex. (The adjacent contacts of the same node and smaller node numbers are preferentially traversed.) input the first behavior integer n (0 <n <100), indicating the number of data groups.
For each group of data, the first row is three integers k, m, t (0 <k <m <(k-1) * k/<t <k ), it indicates that there are m edges and k vertices. t indicates the starting vertex of traversal.
In the following m rows, each row is a space-separated integer u, v, indicating a undirected edge connecting u and v vertex. The output contains n rows, which correspond to n sets of outputs. Each row is a k integer separated by spaces and corresponds to a group of data, which indicates the traversal result of BFS. Sample Input
16 7 00 30 41 41 52 32 43 5
Sample output
0 3 4 2 5 1
The prompt shows that the storage structure is an adjacent matrix. Source sample program
#include
#include
#include
int map[110][110];int dis[110];int vis[110];int k,m,t;int in=1;int out=0;void Bfs(int u){ int i=0; out++; for(i=0;i