#include
#include
#include
using namespace std;
vector<vector> adjMatrix = {
//{0,1,1,1,0,0,0,0,0},//0
//{1,0,0,0,0,0,0,0,0},//1
//{1,0,0,0,0,0,0,0,0},//2
//{1,0,0,0,1,0,0,0,0},//3
//{0,0,0,1,0,0,0,0,0},//4
//{0,0,0,0,0,0,1,1,0},//5
//{0,0,0,0,0,1,0,1,1},//6
//{0,0,0,0,0,1,1,0,0},//7
//{0,0,0,0,0,0,1,0,0},//8
{ 0,1,1,0,0,0,0 },
{ 1,0,0,1,1,0,0 },
{ 1,0,0,0,0,0,1 },
{ 0,1,0,0,0,1,0 },
{ 0,1,0,0,0,1,0 },
{ 0,0,0,1,1,0,1 },
{ 0,0,1,0,0,1,0 },
};
vector visited(adjMatrix.size(), false); // 방문했으면 true, 아니면 false 를 가지고 있는 리스트
stack stk;
void dfs(int start){
stk.push(start);
visited[start] = true;
while (stk.size() != 0) {
int flag = 0;
int cur = stk.top();
stk.pop();
cout << "visit : " << cur << endl;
for (int i = 0; i < adjMatrix.size(); i++) {
if (adjMatrix[cur][i] == 1 && !visited[i]) {
stk.push(i);
visited[i] = true;
flag = 1;
break;
}
}
if (flag == 0) break;
}
}
void dfsAll() {
dfs(0);
for (int i = 0; i < visited.size(); i++) {
if (!visited[i]) dfs(i);
}
}
int main() {
dfsAll();
}