Skip to content

Instantly share code, notes, and snippets.

@dotapetro
Created April 28, 2017 19:28
Show Gist options
  • Save dotapetro/8816403c3e1dba736e8116e184b9c9f5 to your computer and use it in GitHub Desktop.
Save dotapetro/8816403c3e1dba736e8116e184b9c9f5 to your computer and use it in GitHub Desktop.
size, node = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(size)]
def get_nodes_list(graph):
return [[neighbour for neighbour in range(len(row)) if row[neighbour]] for row in graph]
def make_dict(graph):
nodes = get_nodes_list(graph)
return {i: nodes[i] for i in range(len(nodes))}
def print_dict(graph):
nodes = get_nodes_list(graph)
[print("{:^3}".format(i), nodes[i]) for i in range(len(nodes))]
def dfs(graph, visited, node=0):
n = len(graph)
visited[node] = True
print("we are at the ", node, "level")
for i in range(n):
if graph[node][i] and not visited[i]:
print(node, i, "- getting deeper")
dfs(data, visited, i)
visit_list = [False for _ in range(size)]
dfs(data, visit_list, node)
print("total: ", sum(visit_list))
print("here`s our graph: ")
print_dict(data)
# Их правда 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment