#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define MAX 30
#define var 9
int matrice[MAX][MAX];
int v[var];
void citire() {
printf("Introduceti matricea:\n");
for (int i = 0; i < var; i++) {
for (int j = 0; j < var; j++) {
printf("Elementul matricei [%d][%d] = ", i + 1, j + 1);
scanf("%d", &matrice[i][j]);
}
}
}
void afisare() {
printf("\nMatricea este:\n");
for (int i = 0; i < var; i++) {
for (int j = 0; j < var; j++) {
printf("%d ", matrice[i][j]);
}
printf("\n");
}
}
void parcurgerea_latime(int a) {
bool visited[var] = {0};
visited[a] = 1;
int queue[var];
int front = 0;
int rear = 0;;
queue[rear] = a;
printf("Parcurgerea in latime este: %d ", a + 1);
while (front <= rear) {
int node = queue[front];
front++;
for (int i = 0; i < var; i++) {
if (matrice[node][i] == 1 && visited[i] == 0) {
visited[i] = 1;
rear++;
queue[rear] = i;
printf("%d ", i + 1);
}
}
}
}
int main(void) {
citire();
afisare();
int n;
printf("Introduceti varful de parcurgere ");
scanf("%d", &n);
n = n - 1;
parcurgerea_latime(n);
return 0;
}