-
-
Save drygdryg/f54c85df18c23a568b86b7ed5d2a4562 to your computer and use it in GitHub Desktop.
Решение задачи D городской олимпиады по информатике (г. Луганск, 2019 г.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n, s = map(int, input().split()) | |
def dfs(graph, start, visited=set()): | |
if start not in visited: | |
visited.add(start) | |
for node in graph[start]: | |
dfs(graph, node, visited) | |
return visited | |
graph = dict() | |
for i in range(n): | |
graph[i+1] = [] | |
layer = [int(i) for i in input().split()] | |
for j in range(len(layer)): | |
if layer[j] == 1: | |
graph[i+1].append(j+1) | |
res = dfs(graph, s) | |
print(len(res)-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment