From c9468b320bdeb92a82cd791e3890c6c67362d6e1 Mon Sep 17 00:00:00 2001 From: justcoding121 Date: Sat, 10 Oct 2020 05:05:09 -0600 Subject: [PATCH] Update MColorer.cs --- .../Graph/Coloring/MColorer.cs | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Advanced.Algorithms/Graph/Coloring/MColorer.cs b/src/Advanced.Algorithms/Graph/Coloring/MColorer.cs index 975a6ddb..b5f0aeaa 100644 --- a/src/Advanced.Algorithms/Graph/Coloring/MColorer.cs +++ b/src/Advanced.Algorithms/Graph/Coloring/MColorer.cs @@ -14,32 +14,26 @@ public class MColorer /// public MColorResult Color(IGraph graph, C[] colors) { - var totalProgress = new Dictionary, C>(); + var progress = new Dictionary, C>(); foreach (var vertex in graph.VerticesAsEnumberable) { - var progress = canColor(vertex, colors, - new Dictionary, C>(), - new HashSet>()); - - foreach(var item in progress) + if (!progress.ContainsKey(vertex)) { - if (!totalProgress.ContainsKey(item.Key)) - { - totalProgress.Add(item.Key, item.Value); - } + canColor(vertex, colors, + progress, + new HashSet>()); } - } - if (totalProgress.Count != graph.VerticesCount) + if (progress.Count != graph.VerticesCount) { return new MColorResult(false, null); } var result = new Dictionary>(); - foreach (var vertex in totalProgress) + foreach (var vertex in progress) { if (!result.ContainsKey(vertex.Value)) {