задача 1334

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
n, m = map(int, input().split())
graph = [[1000000000000 for i in range(n)] for j in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
graph[a-1][b-1] = c
graph[b-1][a-1] = c
for k in range(n):
for i in range(n):
for j in range(n):
if graph[i][k] + graph[k][j] < graph[i][j]:
graph[i][j] = graph[i][k] + graph[k][j]
for i in range(n):
for j in range(n):
if graph[i][j] == 1000000000000:
graph[i][j] = -1
if i == j:
graph[i][i] = 0
print(max([max(i) for i in graph]))