using System;
using System.Collections.Generic;
public class GFG{
static int maxindex(int[] dist, int n)
{
int mi = 0;
for(int i = 0; i < n; i++)
{
if (dist[i] > dist[mi])
mi = i;
}
return mi;
}
static void selectKcities(int n, int[,] weights,
int k)
{
int[] dist = new int[n];
List<int> centers = new List<int>();
for(int i = 0; i < n; i++)
{
dist[i] = Int32.MaxValue;
}
// Index of city having the
// maximum distance to it's
// closest center
int max = 0;
for(int i = 0; i < k; i++)
{
centers.Add(max);
for(int j = 0; j < n; j++)
{
// Updating the distance
// of the cities to their
// closest centers
dist[j] = Math.Min(dist[j],
weights[max,j]);
}
// Updating the index of the
// city with the maximum
// distance to it's closest center
max = maxindex(dist, n);
}
// Printing the maximum distance
// of a city to a center
// that is our answer
Console.WriteLine(dist[max]);
// Printing the cities that
// were chosen to be made
// centers
for(int i = 0; i < centers.Count; i++)
{
Console.Write(centers[i] + " ");
}
Console.Write("\n");
}
// Driver Code
static public void Main (){
int n = 4;
int[,] weights = new int[,]{ { 0, 4, 8, 5 },
{ 4, 0, 10, 7 },
{ 8, 10, 0, 9 },
{ 5, 7, 9, 0 } };
int k = 2;
// Function Call
selectKcities(n, weights, k);
}
}
// This code is contributed by avanitrachhadiya2155.