原题复刻
思想的火花
1.dfs(邻接矩阵实现)
void dfs(graph &g,int v)
{
cout<=0; w=nextadjves(g,v,w))if(!vis[w])dfs(g,w);
}
2.其他函数介绍请移步HNUST-OJ -1963-邻接矩阵表示法:
代码实现
#includeusing namespace std; #define MAX 100 typedef int VerTexType; typedef int Arctype; typedef struct { VerTexType vexs[MAX]; Arctype arcs[MAX][MAX]; int vexnum,arcnum; }graph; bool vis[MAX]; VerTexType vertexdata(const graph &g,int i) { return g.vexs[i]; } int firstadjves(const graph &g,int v) { for(int j=0; j >g.vexnum; for(int i=0; i >g.arcs[i][j]; } } void dfs(graph &g,int v) { cout< =0; w=nextadjves(g,v,w))if(!vis[w])dfs(g,w); } int main() { graph g; createudg(g); dfs(g,0); }



