From b526c648c4f7e081b6699dfe73f396ee98790d89 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 17 May 2021 23:37:23 +0200 Subject: [PATCH] Add error check to kruskals --- exam_template/python/Graph.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exam_template/python/Graph.py b/exam_template/python/Graph.py index 4f9647c..341c70a 100644 --- a/exam_template/python/Graph.py +++ b/exam_template/python/Graph.py @@ -2,7 +2,7 @@ from sys import argv from pathlib import Path from math import sin, cos, pi -from common import printc, replaceContent +from common import printc, printerr, replaceContent class Matrix: """ Adjacency matrix which supports 0 and 1 """ @@ -127,6 +127,10 @@ class Graph: edges = [] connected_subgraphs = [set(v) for v in self.nodes] + if not all(n in ''.join(x+y for x,y in self.edges) for n in self.nodes): + printerr('Not all nodes are connected. There is no spanning tree to be made') + return + def find_subgraph_containing(v): return [x for x in connected_subgraphs if v in x][0]