Ejemplo n.º 1
0
        public long FindMinimumLatency(string[] lines)
        {
            var graph = new Graph();
            graph.Parse(lines.Skip(2).ToArray());
            var clientVerticesLabels = lines[1].Split(' ');
            var clientVertices = new HashSet<Vertex>(clientVerticesLabels.Select(vertexLabel => graph[vertexLabel]));
            long minimumLatency = long.MaxValue;

            foreach (var currentVertex in graph.Vertices.Where(vertex => !clientVertices.Contains(vertex)))
            {
                var roadmap = graph.Dijkstra(currentVertex);
                var currentMinimumLatency = clientVertices.Max(x => roadmap[x].Distance);
                if (currentMinimumLatency < minimumLatency)
                {
                    minimumLatency = currentMinimumLatency;
                }
            }

            return minimumLatency;
        }