Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int g[4][4] = {
- {0, 1, 1, 0},
- {1, 0, 0, 0},
- {1, 0, 0, 1},
- {0, 0, 1, 0},
- };
- int used[4];
- void DFS(int v) {
- cout << v + 1 << " ";
- used[v] = true;
- for (int j = 0; j < 4; ++ j) {
- if (g[v][j] != 0 && !used[j]) DFS(j);
- }
- }
- int main() {
- for (int i = 0; i < 4; ++ i)
- if (!used[i]) {
- DFS(i);
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement