#include <stdio.h>
#include <memory.h>
#define FIN "graph.in"
#define FOUT "bfs.out"
#define DIM 30
//Breadth First Search
void bfs(int mat[][DIM], int n, int startNode) {
int explored[DIM],
Q[DIM],
first, last,
node;
memset(explored
, 0, sizeof(explored
));
Q[0] = startNode;
first = last = 0;
explored[startNode] = 1;
while( first <= last ) {
node = Q[first];
for(int j = 0; j < n; ++j) {
//is adjcency and not explored execute
if(explored[ j ]==0 && mat[ node ][ j ]==1) {
Q[ ++last ] = j;
explored[ j ] = 1;
}
}
first++;
}
printf("Breadh First Search:\n");
for(int j = 0; j < n;++j) {
}
}
int main(int argc, char const *argv[]) {
int matrix[DIM][DIM], nodes, i, j;
//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) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
*/
startNode = 2;
bfs( matrix, nodes, startNode );
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtZW1vcnkuaD4KI2RlZmluZSBGSU4gImdyYXBoLmluIgojZGVmaW5lIEZPVVQgImJmcy5vdXQiCiNkZWZpbmUgRElNIDMwCgovL0JyZWFkdGggRmlyc3QgU2VhcmNoCnZvaWQgYmZzKGludCBtYXRbXVtESU1dLCBpbnQgbiwgaW50IHN0YXJ0Tm9kZSkgewoKICAgICBpbnQgZXhwbG9yZWRbRElNXSwKICAgICAgICAgUVtESU1dLAogICAgICAgICBmaXJzdCwgbGFzdCwKICAgICAgICAgbm9kZTsKCiAgICAgbWVtc2V0KGV4cGxvcmVkLCAwLCBzaXplb2YoZXhwbG9yZWQpKTsKCiAgICAgUVswXSA9IHN0YXJ0Tm9kZTsKCiAgICAgZmlyc3QgPSBsYXN0ID0gMDsKCiAgICAgZXhwbG9yZWRbc3RhcnROb2RlXSA9IDE7CgogICAgIHdoaWxlKCBmaXJzdCA8PSBsYXN0ICkgewoKICAgICAgIG5vZGUgPSBRW2ZpcnN0XTsKCiAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgbjsgKytqKSB7CgogICAgICAgICAgLy9pcyBhZGpjZW5jeSBhbmQgbm90IGV4cGxvcmVkICBleGVjdXRlCiAgICAgICAgICAgaWYoZXhwbG9yZWRbIGogXT09MCAmJiBtYXRbIG5vZGUgXVsgaiBdPT0xKSB7CgogICAgICAgICAgICAgUVsgKytsYXN0IF0gPSBqOwoKICAgICAgICAgICAgIGV4cGxvcmVkWyBqIF0gPSAxOwogICAgICAgICAgIH0KICAgICAgIH0KCiAgICAgICBmaXJzdCsrOwogICAgIH0KCiAgICAgcHJpbnRmKCJCcmVhZGggRmlyc3QgU2VhcmNoOlxuIik7CgogICAgIGZvcihpbnQgaiA9IDA7IGogPCBuOysraikgewoKICAgICAgIHByaW50ZigiJWQgIiwgUVtqXSsxKTsKCiAgICAgfQoKICAgICBwcmludGYoIlxuIik7Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyIGNvbnN0ICphcmd2W10pIHsKCiAgaW50IG1hdHJpeFtESU1dW0RJTV0sIG5vZGVzLCBpLCBqOwoKICAvL2ZyZW9wZW4oRklOLCAiciIsIHN0ZGluKTsKICBpbnQgc3RhcnROb2RlOwogIC8vZnJlb3BlbihGT1VULCAidyIsIHN0ZG91dCk7CiAgc2NhbmYoIiVkIiwgJm5vZGVzKTsKCiAgZm9yKGkgPSAwOyBpIDwgbm9kZXM7ICsraSkgewogICAgZm9yKGogPSAwOyBqIDwgbm9kZXM7ICsraikgewogICAgICBzY2FuZigiJWQiLCAmbWF0cml4W2ldW2pdKTsKICAgIH0KICB9CgogIC8vRGlzcGxheSBtYXRyaXggYWRqY2VuY3kKICAvKgogIGZvcihpID0gMDsgaSA8IG5vZGVzOyArK2kpIHsKICAgIGZvcihqID0gMDsgaiA8IG5vZGVzOyArK2opIHs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