#include<iostream>
#include<vector>
#include<stack>
using namespace std;
bool vis[6];
int g[6][6] = {
{0,1,0,0,0,0},
{1,0,1,0,1,0},
{0,1,0,1,0,0},
{0,0,1,0,0,0},
{0,1,0,0,0,1},
{0,0,0,0,1,0}
};
void dfs(int cur) {
cout << char(cur + 'A');
vis[cur] = 1;
for (int i = 0; i < 6; i++)
{
if (g[cur][i] == 1 && !vis[i])
dfs(i);
}
}
int main() {
dfs(0);
return 0;
}
图的深度优先搜素
最新推荐文章于 2024-08-31 15:34:19 发布