HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > C. T. 2011 > problem:


Connected components

Volume problems

• Cow PinBall
• Cow Sorting
• Maximum Sum
• Making Change
• Colored hills
• Word Statistics
• Going to the Movies
• A to the power of B
• Connected components
• Binary transformations
• Fleas
• Babel tower
• Pizza delivery
• Railway turnout
• Door lock
• Maze
• Skiers

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 1000/1000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.

Problem description

Calculate number of connected components in undirected graph.

Input

There is a single integer on the first line of input N (1 <= N <= 100), then N lines with N integers 0 or 1 (adjacency matrix of graph).

Output

Write number of connected components.

Example

stdin stdout

6

0 1 1 0 0 0
1 0 1 0 0 0
1 1 0 0 0 0
0 0 0 0 1 0
0 0 0 1 0 0
0 0 0 0 0 0

3

Для отправки решений необходимо выполнить вход.

www.contester.ru