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

i also need the solution of this question :(

i also need the solution of this question :(

ariel930 , can you show us how much have you tried ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.