Пример #1
0
        public static void MainTest(string[] args)
        {
            int V1 = int.Parse(args[0]);
            int V2 = int.Parse(args[1]);
            int E  = int.Parse(args[2]);
            int F  = int.Parse(args[3]);

            Bipartite b;
            // create random bipartite graph with V1 vertices on left side,
            // V2 vertices on right side, and E edges; then add F random edges
            Graph G = GraphGenerator.Bipartite(V1, V2, E);

            Console.WriteLine("Graph is {0}\n", G);

            b = new Bipartite(G);
            BipartiteReport(b);

            for (int i = 0; i < F; i++)
            {
                int v = StdRandom.Uniform(V1 + V2);
                int w = StdRandom.Uniform(V1 + V2);
                G.AddEdge(v, w);
            }
            Console.WriteLine("After adding {0} random edges", F);
            Console.WriteLine("Graph is {0}\n", G);

            b = new Bipartite(G);
            BipartiteReport(b);
        }
Пример #2
0
 private static void BipartiteReport(Bipartite b)
 {
     if (b.IsBipartite)
     {
         Graph G = b.G;
         Console.WriteLine("Graph is bipartite");
         for (int v = 0; v < G.V; v++)
         {
             Console.WriteLine(v + ": " + b.Color(v));
         }
     }
     else
     {
         Console.Write("Graph has an odd-length cycle: ");
         foreach (int x in b.OddCycle())
         {
             Console.Write(x + " ");
         }
     }
     Console.WriteLine();
 }