邻接矩阵存储图的深度优先遍历
题目描述
试实现邻接矩阵存储图的深度优先遍历。
输入
第一行n为顶点数,第二行至第n+2行为其邻接矩阵表示形式,最后一行为遍历的起始点。
输出
见样例
输入样例:
7
0 0 1 1 1 0 0
0 0 0 1 0 1 0
1 0 0 1 0 1 0
1 1 1 0 0 0 0
1 0 0 0 0 1 0
0 1 0 0 1 0 1
0 0 0 0 0 1 0
5
输出样例:
DFS from 5: 5 1 3 0 2 4 6
参考代码:
#include <bits/stdc++.h>
using namespace std;
void DFS(int **p, int n, int start, bool *visited, vector<int> &result) {
visited[start] = true;
for (int i =<