mirea-projects/Second term/Algorithms/6/2-1.py

33 lines
782 B
Python
Raw Permalink Normal View History

2024-09-23 23:22:33 +00:00
def remover(nodes: list[int], graph: list[list[int]], pnode: int) -> None:
for node in nodes:
if graph[pnode][node]:
nodes.remove(node)
remover(nodes, graph, node)
def main() -> None:
graph = [
[0, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 0],
[1, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 1, 0, 0, 0, 0, 0]
]
nodes = [0, 1, 2, 3, 4, 5, 6, 7]
count = 0
while len(nodes) != 0:
count += 1
index = nodes[0]
nodes.remove(index)
remover(nodes, graph, index)
print("Connectivity score:", count)
if __name__ == "__main__":
main()