Beispiel #1
0
        public GraphProperties(Graph graph)
        {
            this.graph = graph;

            BfsPaths bfsPaths = new BfsPaths(graph, 0);

            for (int v = 0; v < graph.V; v++)
            {
                pathLens.Add(v, bfsPaths.HasPathTo(v) ? bfsPaths.DistTo(v) : -1);
            }

            int max = int.MinValue;
            int min = int.MaxValue;

            foreach (var kvp in pathLens)
            {
                if (kvp.Value == -1)
                {
                    continue;
                }

                if (kvp.Value > max)
                {
                    max            = kvp.Value;
                    maxVertexIndex = kvp.Key;
                }

                if (kvp.Value < min)
                {
                    min            = kvp.Value;
                    minVertexIndex = kvp.Key;
                }
            }

            if (max == int.MinValue)
            {
                maxVertexIndex = -1;
            }

            if (min == int.MaxValue)
            {
                minVertexIndex = -1;
            }
        }