HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > C. T. 2011 > problem:


Connected components

Volume problems

• Dijkstra
• Tickets
• Flowers
• Bookshelf
• Coin Game
• Cow PinBall
• Cow Sorting
• Colored hills
• Connected components
• Going to the Movies
• Word power
• Word Statistics
• Brackets
• Profits
• Triangle
• Istanbul
• Butterfly

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