Beispiel #1
0
 private bool BicolorateInternal(int[] colors, int i, int color)
 {
     if (colors[i] == 0)
     {
         if (color == 1)
         {
             LeftVertices.Add(i);
         }
         else
         {
             RightVertices.Add(i);
         }
         colors[i] = color;
     }
     else if (colors[i] != color)
     {
         return(false);
     }
     else
     {
         return(true);
     }
     foreach (var j in Edges[i])
     {
         if (!BicolorateInternal(colors, j, 3 - color))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #2
0
    private void FindVertexCover()
    {
        FindBipartiteMatching();

        var TreeSet = new HashSet <int>();

        foreach (var v in LeftVertices)
        {
            if (Matching[v] < 0)
            {
                DepthFirstSearch(TreeSet, v, false);
            }
        }

        VertexCoverResult = new HashSet <int>(LeftVertices.Except(TreeSet).Union(RightVertices.Intersect(TreeSet)));
    }