eolymp
bolt
Try our new interface for solving problems
Problems

Depth Search

Depth Search

The undirected unweighted graph with one selected vertex is given. Find the number of vertices in the connected component where the selected vertex (including the selected vertex). \InputFile The first line contains the number of vertices $n$ and the selected vertex $s~(1 \le s \le n \le 100)$. In the next $n$ lines given $n$ integers --- the adjacency matrix of a graph, where $"0"$ means the absence of an edge, and $"1"$ means the presence of an edge. It is guaranteed that the main diagonal of the matrix contains zeros. \OutputFile Print the desired number of vertices. \includegraphics{https://static.e-olymp.com/content/d9/d97cb45ab10aebba059f56ed310a51133058be2b.gif}
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 1
0 1 1 0 0
1 0 1 0 0
1 1 0 0 0
0 0 0 0 1
0 0 0 1 0
Output example #1
3
Input example #5
10 1
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Output example #5
2