
giveMeRadius
Given a connected undirected weighted graph (possibly with cycles) as its adjacency matrix
, calculate its radius.
The radius of a graph is the minimum eccentricity of any vertex, where the eccentricity of a vertex v
is the greatest distance between v
and any other vertex.
For more information on how distances are calculated, check out this page.
Example
- For
matrix = [[-1, -1, 1, 3],
[-1, -1, -1, 2], [1, -1, -1, 7], [3, 2, 7, -1]]
the output should begiveMeRadius(matrix) = 4
.
In this example eccentricity of the first vertex is5
, the second vertex is6
, the third vertex is6
, and the fourth vertex is4
. So,radius = min({5,6,6,4}) = 4
.
Input/Output
-
[execution time limit] 0.5 seconds (cpp)
-
[input] array.array.integer matrix
Adjacency matrix of the given graph, which is guaranteed to be symmetric. If
matrix[i][j] > 0
, the distance between verticesi
andj
ismatrix[i][j]
. Otherwisematrix[i][j] = -1
, meaning that there’s no edge between verticesi
andj
.Constraints:
2 ≤ matrix.length < 10
,matrix[i][j] = matrix[j][i]
,matrix[i][i] = -1
,matrix[0].length = matrix.length
,-1 ≤ matrix[i][j] < 100
. -
[output] integer
- Radius of the given graph.
Post Comment