Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n, s = map(int, input().split())
- adj = []
- while n:
- adj.append(list(map(int, input().split())))
- n -= 1
- s -= 1 # convert to zero-based
- st = [s]
- res = 0
- visited = [0] * len(adj)
- visited[s] = 1
- while st:
- cur = st.pop()
- res += 1
- for v, edge in enumerate(adj[cur]):
- if edge and not visited[v]:
- st.append(v)
- visited[v] = 1
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement