//Depth First Search Traversal
#include <stdio.h>
#include <memory.h>
#define FIN "graph.in"
#define FOUT "bfs.out"
#define DIM 30
int matrix[DIM][DIM], nodes,
i, j,
explored[DIM];
void dfs(int node) {
explored[node] = 1;
for(int i = 0; i <nodes;++i) {
if(matrix[node][i] == 1 && explored[i] == 0) {
dfs(i);
}
}
}
int main(int argc, char const *argv[]) {
//freopen(FIN, "r", stdin);
int startNode;
//freopen(FOUT, "w", stdout);
for(i = 0; i < nodes; ++i) {
for(j = 0; j < nodes; ++j) {
scanf("%d", &matrix
[i
][j
]); }
}
//Display matrix adjcency
for(i = 0; i < nodes; ++i) {
for(j = 0; j < nodes; ++j) {
}
}
startNode = 1;
dfs( startNode );
return 0;
}
Ly9EZXB0aCBGaXJzdCBTZWFyY2ggVHJhdmVyc2FsCiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8bWVtb3J5Lmg+CiNkZWZpbmUgRklOICJncmFwaC5pbiIKI2RlZmluZSBGT1VUICJiZnMub3V0IgojZGVmaW5lIERJTSAzMAoKaW50IG1hdHJpeFtESU1dW0RJTV0sIG5vZGVzLAogICAgaSwgaiwKICAgIGV4cGxvcmVkW0RJTV07Cgp2b2lkIGRmcyhpbnQgbm9kZSkgewoKICAgICBwcmludGYoIiVkICIsIG5vZGUgKyAxKTsKCiAgICAgZXhwbG9yZWRbbm9kZV0gPSAxOwoKICAgICBmb3IoaW50IGkgPSAwOyBpIDxub2RlczsrK2kpIHsKCiAgICAgICAgIGlmKG1hdHJpeFtub2RlXVtpXSA9PSAxICYmIGV4cGxvcmVkW2ldID09IDApIHsKCiAgICAgICAgICAgZGZzKGkpOwogICAgICAgICB9CiAgICAgfQp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciBjb25zdCAqYXJndltdKSB7CgogIC8vZnJlb3BlbihGSU4sICJyIiwgc3RkaW4pOwogIGludCBzdGFydE5vZGU7CiAgLy9mcmVvcGVuKEZPVVQsICJ3Iiwgc3Rkb3V0KTsKICBzY2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