0

Hi.here is a question I got for assignment.I am stuck in this for hours and couldnt com up with any logic.Any help will be highly appreciated.Thanks

Depth-First-Search
Q.No.1 The undirected unweighted graph with one selected vertex is given. Find the number of
vertices in the connected component where the selected vertex belong (including the selected one).
Specifications
Input
The first line contains two integers n and s (1 ≤ s ≤ n ≤ 100), where n - the number of vertices of the
graph, and s - chosen vertex. The following n lines contains n numbers - the adjacency matrix of the
graph in the MDM figure "0" means no edges between vertices, and the number "1" - its availability. It is
guaranteed that the main diagonal of the matrix are always zero.
Output
Print the desired number of vertices

Example input
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
Example output

3

3
Contributors
3
Replies
17
Views
3 Years
Discussion Span
Last Post by mridul.ahuja
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.