#include <iostream>
using namespace std;
int n = 3;
int graph[3][3] = {
{1,1,0},
{0,1,0},
{1,0,1}
};
bool visited[3][3];
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
void dfs(int x, int y){
visited[x][y] = true;
cout << x << " " << y << "\n";
for(int k=0; k<4; k++){
int nx = x + dx[k];
int ny = y + dy[k];
if(nx >= 0 && nx < n && ny >= 0 && ny < n){
if(graph[nx][ny] == 1 && !visited[nx][ny]){
dfs(nx, ny);
}
}
}
}
int main(){
dfs(0,0);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: