Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n, s = list(map(int, input().split()))
- graph = [[] for i in range(n)]
- for i in range(n):
- arr = list(map(int, input().split()))
- for j in range(n):
- if arr[j] == 1:
- graph[i].append(j)
- ans = 1
- used = [False for i in range(n)]
- used[s - 1] = True
- def dfs(s):
- global ans, used, graph
- for i in range(len(graph[s])):
- if used[graph[s][i]] == False:
- used[graph[s][i]] = True
- ans += 1
- dfs(graph[s][i])
- return
- dfs(s - 1)
- print(ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement