Skip to content

Instantly share code, notes, and snippets.

@drygdryg
Last active December 9, 2019 09:57
Show Gist options
  • Save drygdryg/f54c85df18c23a568b86b7ed5d2a4562 to your computer and use it in GitHub Desktop.
Save drygdryg/f54c85df18c23a568b86b7ed5d2a4562 to your computer and use it in GitHub Desktop.
Решение задачи D городской олимпиады по информатике (г. Луганск, 2019 г.)
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