Пример #1
0
        static int[] getWindMillGraph(List <List <int> > graph)
        {
            int size = graph.Count;

            if (size < 5)
            {
                return(null);
            }
            int  centerNodeDegree    = size - 1;
            int  centerNode          = -1;
            int  completeGraphDegree = -1;
            bool isNotAllEqual       = false;

            for (int i = 0; i < size; i++)
            {
                int degree = graph[i].Count(isEdge => isEdge == 1);
                if (degree == centerNodeDegree && centerNode == -1)
                {
                    centerNode = i;
                }
                else if (completeGraphDegree == -1)
                {
                    completeGraphDegree = degree;
                }
                else if (completeGraphDegree != degree)
                {
                    isNotAllEqual = true;
                    break;
                }
            }
            if (isNotAllEqual)
            {
                return(null);
            }
            ColoredGraph coloredGraph     = new ColoredGraph(graph);
            int          n                = coloredGraph.colorQuantity;
            int          nodeEachSubGraph = n - 1;

            if (nodeEachSubGraph != completeGraphDegree || nodeEachSubGraph < 2)
            {
                return(null);
            }
            int k     = (size - 1) / nodeEachSubGraph;
            int nodes = n * k - k + 1;

            if (size != nodes)
            {
                return(null);
            }
            return(new int[] { n, k });
        }
Пример #2
0
        static void checkGraph(string fileName = "input.txt")
        {
            try
            {
                // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader(fileName))
                {
                    // Read the stream to a string, and write the string to the console.
                    int size = Int32.Parse(sr.ReadLine());
                    List <List <int> > graph = new List <List <int> >();
                    for (int i = 0; i < size; i++)
                    {
                        List <int> row    = new List <int>();
                        string     line   = sr.ReadLine();
                        string[]   values = line.Split(' ');
                        Array.ForEach(values, v => row.Add(Int32.Parse(v)));
                        graph.Add(row);
                    }

                    ColoredGraph coloredGraph      = new ColoredGraph(graph);
                    bool         isBiGraph         = coloredGraph.maxColor == 1;
                    bool         isCompleteBiGraph = true;
                    if (isBiGraph)
                    {
                        foreach (int v1 in coloredGraph.groupColor[0])
                        {
                            foreach (int v2 in coloredGraph.groupColor[1])
                            {
                                if (graph[v1][v2] == 0)
                                {
                                    isCompleteBiGraph = false;
                                    break;
                                }
                            }
                            if (!isCompleteBiGraph)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        isCompleteBiGraph = false;
                    }
                    bool   isStarGraph      = Program.checkStarGraph(graph);
                    bool   isButterFlyGraph = Program.checkButterFlyGraph(graph);
                    int[]  mindWillProps    = Program.getWindMillGraph(graph);
                    bool   isKParties       = !isBiGraph && graph.Count != 0;
                    string kParties         = "";
                    if (isKParties)
                    {
                        kParties = coloredGraph.maxColor + 1 + "-partie";
                        foreach (var colorGroup in coloredGraph.groupColor)
                        {
                            kParties += " {" + String.Join(", ", colorGroup.Value.ToArray()) + "}";
                        }
                    }
                    int wheel = Program.getWheelGraph(graph);
                    Console.WriteLine("Đồ thị lưỡng phân: {0}", isBiGraph ? "{" + String.Join(", ", coloredGraph.groupColor[0].ToArray()) + "} {" + String.Join(", ", coloredGraph.groupColor[1].ToArray()) + "}" : "Không");
                    Console.WriteLine("Đồ thị lưỡng phân đầy đủ: {0}", isCompleteBiGraph && graph.Count > 0 ? "Có" : "Không");
                    Console.WriteLine("Đồ thị rỗng: {0}", graph.Count == 0 ? "Có" : "Không");
                    Console.WriteLine("Đồ thị hình sao: {0}", isStarGraph ? "S" + graph.Count : "Không");
                    Console.WriteLine("Đồ thị bánh xe: {0}", wheel != -1 ? "W" + wheel : "Không");
                    Console.WriteLine("Đồ thị hình bướm: {0}", isButterFlyGraph ? "Có" : "Không");
                    Console.WriteLine("Đồ thị hình cối xay gió: {0}", mindWillProps != null ? "Wd(" + mindWillProps[0] + ", " + mindWillProps[1] + ")" : "Không");
                    Console.WriteLine("Đồ thị k-phân: {0}", isKParties ? kParties : "Không");
                    Console.WriteLine("");
                    //Environment.Exit(0);
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }