Cod sursa(job #421603)

Utilizator mathboyDragos-Alin Rotaru mathboy Data 21 martie 2010 14:49:12
Problema Copii Scor 0
Compilator cpp Status done
Runda Algoritmiada 2010, Runda 4, Clasele 9-10 Marime 0.54 kb
#include <cstdio>
#define nmax 30


using namespace std;

int A [nmax][nmax], N, viz [nmax], muchie;
void df (int node) {

	viz [node] = 1;
	for (int i = 1; i <= N; i++)
		if (A [node][i])
			if (!viz [i]) {
				df (i);
				++muchie;
			}
}
int main () {

	freopen ("copii.in", "r", stdin);
	freopen ("copii.out", "w", stdout);
	scanf ("%d\n", &N);
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			scanf ("%d", &A [i][j]);
	for (int i = 1; i <= N; i++)
		if (!viz [i]) {
			df (i);
			++muchie;
		}
	printf ("%d\n", muchie);
	return 0;
}