задача 1335

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
n, m = list(map(int, input().split()))
inf = 9999999999
a=[[inf]*(n+1) for i in range(n+1)]
for i in range(m):
t=list(map(int, input().split()))
a[t[0]][t[1]]=t[2]
a[t[1]][t[0]]=t[2]
for k in range(1, n+1):
for i in range(1, n+1):
for j in range(1, n+1):
if a[i][k]+a[k][j]<a[i][j]:
a[i][j]=a[i][k]+a[k][j]
mx=[0]*(n+1)
for i in range(1, n+1):
for j in range(1, n+1):
if a[i][j]>mx[i]:
mx[i]=a[i][j]
res=inf
j=1
for i in range(1, n+1):
if mx[i]<res:
res=mx[i]
j=i
print(j)
'''
n, m = [int(s) for s in input().split()]
min_dist = [[float('+inf')]*n for i in range(n)]
for i in range(m):
a = [int(s) for s in input().split()]
min_dist[a[0]-1][a[1]-1] = a[2]
min_dist[a[1]-1][a[0]-1] = a[2]
for k in range(n):
for i in range(n):
for j in range(n):
if i == j:
min_dist[i][j] = 0
else:
min_dist[i][j] = min(min_dist[i][j], min_dist[i][k]+min_dist[k][j])
c, e = float('+inf'), 1
for i in range(n):
d = max(min_dist[i])
if d < c:
c, e = d, i+1
print(e)
'''