#include <iostream>
#include <vector>
using namespace std;
vector<int> graph[10];
bool visited[10];
void dfs(int x) {
visited[x] = true;
cout << x << " ";
for(int i = 0; i < graph[x].size(); i++) {
int next = graph[x][i];
if(visited[next] == false) {
dfs(next);
}
}
}
int main() {
graph[1].push_back(2);
graph[1].push_back(3);
graph[2].push_back(4);
graph[2].push_back(5);
dfs(1);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: