289. Friend Circles
EasyDFSAdjacency Matrix
M[i][j] = 1 means person i and j are friends (the matrix is symmetric with 1s on the diagonal). Print the number of friend circles (connected groups).
Input format
Line 1: n Next n lines: n values
Output format
The number of circles.
Example 1
Input
3 1 1 0 1 1 0 0 0 1
Output
2
Example 2
Input
3 1 0 0 0 1 0 0 0 1
Output
3
Constraints
1 ≤ n ≤ 200
Read input from standard input and print the answer to standard output. Your code is judged against 3 test cases, most of them hidden.
Loading the MyLoginn IDE…