-----Indian National Olympiad in Informatics 2014-----
Nikhil’s slogan has won the contest conducted by Drongo Airlines and he is entitled to a free ticket between any two destinations served by the airline. All cities served by Drongo Airlines can be reached from each other by some sequence of connecting flights. Nikhil is allowed to take as many connecting flights as needed, but he must take the cheapest route between his chosen destinations.
Each direct flight between two cities has a fixed price. All pairs of cities connected by direct flights have flights in both directions and the price is the same in either direction. The price for a sequence of connecting flights is the sum of the prices of the direct flights along the route.
Nikhil has information about the cost of each direct flight. He would like to maximize the value of his prize, so he would like to choose a pair of cities on the network for which the cost of the cheapest route is as high as possible.
For instance, suppose the network consists of four cities {1, 2, 3, 4}, connected as shown on the right.
In this case, Nikhil should choose to travel between 1 and 4, where the cheapest route has cost 19. You can check that for all other pairs of cities, the cheapest route has a smaller cost. For instance, notice that though the direct flight from 1 to 3 costs 24, there is a cheaper route of cost 12 from 1 to 2 to 3.

-----Input Format:-----
- Line 1 : Two space-separated integers, C and F . C is the number of cities on the network, numbered 1, 2, . . . , C. F is the number of pairs of cities connected by a direct flight
- Lines 2 to F + 1 : Each line describes one direct flight between a pair of cities and consists of three integers, x, y and p, where x and y are the two cities connected by this flight and p is the price of this
For all direct flights, $x \neq y$, and no pair of cities is connected by more than one direct flight. If there is a direct flight from x to y with price p, there is also a flight from y to x with price p and exactly one of these two will be listed.

-----Output Format-----
- The output consists of a single integer, the maximum cost among the cheapest routes between all pairs of cities across the airline’s network.

-----Test Data-----
The testdata is grouped into three subtasks. In all subtasks, 2 ≤ C ≤ 230 and 1 ≤ F ≤ 23665. In addition, each subtask has the following constraints on the inputs.
- Subtask 1 (20 marks) : F = C − 1 (that is, the airline network is a tree) and p = 1 for each direct flight.
- Subtask 2 (30 marks) : There is no constraint on the shape of the network, but for each direct flight, p = 1.
- Subtask 3 (50 marks) : There is no constraint on the shape of the network, but for each direct flight, 0 ≤ p ≤ $10^5$.

-----Sample Input-----
4 5
1 2 10
1 3 24
2 3 2
2 4 15
3 4 7

-----Sample Output-----
19

Note: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous output will be treated as incorrect!

Starter code:

Solutions:
c,f=list(map(int,input().split()))
l=[[1000001 for i in range(c)] for j in range(c)] 
while f:
    x,y,cost=list(map(int,input().split()))
    l[x-1][y-1]=cost
    l[y-1][x-1]=cost
    f-=1  
for i in range(c):
    l[i][i]=0
for k in range(c): 
    for x in range(c):
        for y in range(c): 
            if x==k or y==k or x==y:
                continue
            elif x!=y:
                l[x][y]=min(l[x][y],l[x][k]+l[k][y]) 
m=-1 
for i in range(c):
    for j in range(c):
        if m<l[i][j]:
            m=l[i][j]
print(m)
    # cook your dish here


I = int(10e15)
c , f = [int(i) for i in input().split()]
arr = [[0 for i in range(c)] for j in range(c)] 

sdc = []
for x in range(f):
    sdc.append( list(int(x) for x in input().split()))
    
for i in sdc:
    arr[i[0]-1][i[1]-1]=i[2]
    arr[i[1]-1][i[0]-1]=i[2]
    
for x in range(c):
    for y in range(c):
        if x != y :
            if arr[x][y] == 0:
                arr[x][y] = I

def f_w(v, arr):
	for k in range(0, v):
		for i in range(0, v):
			for j in range(0, v):
				arr[i][j] = min(arr[i][j], arr[i][k] + arr[k][j])


f_w(c,arr)
m = -1
for x in range(c):
    m = max(m, max(arr[x]))
           
print(m)

c,f=list(map(int,input().split()))
l=[[1000001 for i in range(c)] for j in range(c)] 
while f:
    x,y,cost=list(map(int,input().split()))
    l[x-1][y-1]=cost
    l[y-1][x-1]=cost
    f-=1  
for i in range(c):
    l[i][i]=0
for k in range(c): 
    for x in range(c):
        for y in range(c): 
            if x==k or y==k or x==y:
                continue
            elif x!=y:
                l[x][y]=min(l[x][y],l[x][k]+l[k][y]) 
m=-1 
for i in range(c):
    for j in range(c):
        if m<l[i][j]:
            m=l[i][j]
print(m)
    # cook your dish here


# cook your dish here
c,f=list(map(int,input().split()))
l=[[1000001 for i in range(c)] for j in range(c)] 
while f:
    x,y,cost=list(map(int,input().split()))
    l[x-1][y-1]=cost
    l[y-1][x-1]=cost
    f-=1  
for i in range(c):
    l[i][i]=0
for k in range(c): 
    for x in range(c):
        for y in range(c): 
            if x==k or y==k or x==y:
                continue
            elif x!=y:
                l[x][y]=min(l[x][y],l[x][k]+l[k][y]) 
m=-1 
for i in range(c):
    for j in range(c):
        if m<l[i][j]:
            m=l[i][j]
print(m)
    


c,f=list(map(int,input().split()))
l=[[1000001 for i in range(c)] for j in range(c)] 
while f:
    x,y,cost=list(map(int,input().split()))
    l[x-1][y-1]=cost
    l[y-1][x-1]=cost
    f-=1  
for i in range(c):
    l[i][i]=0
for k in range(c): 
    for x in range(c):
        for y in range(c): 
            if x==k or y==k or x==y:
                continue
            elif x!=y:
                l[x][y]=min(l[x][y],l[x][k]+l[k][y]) 
m=-1 
for i in range(c):
    for j in range(c):
        if m<l[i][j]:
            m=l[i][j]
print(m)
    


c,f=list(map(int,input().split()))
l=[[100001 for i in range(c)] for j in range(c)] 
while f:
    x,y,cost=list(map(int,input().split()))
    l[x-1][y-1]=cost
    l[y-1][x-1]=cost
    f-=1 
for k in range(c): 
    for x in range(c):
        for y in range(c): 
            if x==k or y==k:
                continue
            elif x!=y:
                l[x][y]=min(l[x][y],l[x][k]+l[k][y]) 
            else:
                l[x][y]=0
m=-1 
for i in range(c):
    for j in range(c):
        if m<l[i][j]:
            m=l[i][j]
print(m)
    


c,f=list(map(int,input().split()))
l=[[100000 for i in range(c)] for j in range(c)] 
while f:
    x,y,cost=list(map(int,input().split()))
    l[x-1][y-1]=cost
    l[y-1][x-1]=cost
    f-=1 
for k in range(c): 
    for x in range(c):
        for y in range(c): 
            if x==k or y==k:
                continue
            elif x!=y:
                l[x][y]=min(l[x][y],l[x][k]+l[k][y]) 
            else:
                l[x][y]=0
m=-1 
for i in range(c):
    for j in range(c):
        if m<l[i][j]:
            m=l[i][j]
print(m)
    


c,f=list(map(int,input().split()))
l=[[10000 for i in range(c)] for j in range(c)] 
while f:
    x,y,cost=list(map(int,input().split()))
    l[x-1][y-1]=cost
    l[y-1][x-1]=cost
    f-=1 
for k in range(c): 
    for x in range(c):
        for y in range(c):
            if x!=y:
                l[x][y]=min(l[x][y],l[x][k]+l[k][y]) 
            else:
                l[x][y]=0
m=-1 
for i in range(c):
    for j in range(c):
        if m<l[i][j]:
            m=l[i][j]
print(m)
    


# cook your dish here
c,n=input().split()
c,n=int(c),int(n)
a=[]
for i in range(c):
    a.append([1000000]*c)
        
while(n>0):
    n-=1 
    x,y,p=input().split()
    x,y,p=int(x)-1,int(y)-1,int(p)
    a[x][y]=a[y][x]=p
    
for k in range(c):
    for i in range(c):
        for j in range(c):
            if(a[i][k]+a[k][j]<a[i][j]):
                a[i][j]=a[i][k]+a[k][j]

mx=0

for i in range(c):
    for j in range(c):
        if(i!=j and mx<a[i][j]):
            mx=a[i][j]


print(mx)
        
        


# cook your dish here
c,n=input().split()
c,n=int(c),int(n)
a=[]
for i in range(c):
    a.append([1000000]*c)
        
while(n>0):
    n-=1 
    x,y,p=input().split()
    x,y,p=int(x)-1,int(y)-1,int(p)
    a[x][y]=a[y][x]=p
    
for k in range(c):
    for i in range(c):
        for j in range(c):
            if(a[i][k]+a[k][j]<a[i][j]):
                a[i][j]=a[i][k]+a[k][j]

mx=0

for i in range(c):
    for j in range(c):
        if(i!=j and mx<a[i][j]):
            mx=a[i][j]


print(mx)
        
        


# cook your dish here
import numpy as np
import sys
import heapq
# class Graph(): 
  
#     def __init__(self, vertices): 
#         self.V = vertices 
#         self.graph = [[0 for column in range(vertices)]  
#                     for row in range(vertices)] 
  
#     def minDistance(self, dist, sptSet, src): 
#         min = sys.maxsize
#         min_index = -1
#         for v in range(self.V): 
#             if dist[v] < min and sptSet[v] == False : 
#                 min = dist[v] 
#                 min_index = v 
  
#         return min_index 

  
#     def dijkstra(self, src): 
        
#         # weights = self.graph[src]
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = 0 
#         #     self.graph[i][src] = 0
            
  
#         dist = [sys.maxsize] * self.V 
#         dist[src] = 0
#         sptSet = [False] * self.V 
  
#         for cout in range(self.V): 
#             u = self.minDistance(dist, sptSet, src) 
#             if u == -1 : continue
#             sptSet[u] = True
#             for v in range(self.V): 
#                 if self.graph[u][v] > 0 and sptSet[v] == False and dist[v] > dist[u] + self.graph[u][v]: 
#                     dist[v] = dist[u] + self.graph[u][v] 
                    
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = weights[i]
#         #     self.graph[i][src] = weights[i]
        
#         dist.remove(0)
#         MINIMUM = np.inf
#         for idx in range(len(dist)):
#             if idx != src and not self.graph[idx][src] and dist[idx] < MINIMUM : 
#                 MINIMUM = dist[idx]
            
#         return MINIMUM

# def findCheapestPrice(n, flights, src , dst ) : 
#     graph = {}

#     for u in range(n):
#         graph[u] = []

#     for u,v,w in flights:
#         graph[u].append((v,w))

#     heap = [(0,-n,src)]
    

#     while heap:
#         (cost,i,u) = heapq.heappop(heap)

#         if u == dst :
#             return cost
#             # if i >= n - 1 : continue
#             # else:  return cost
#             # if u not in list(zip(*graph[src]))[0] : return cost

#         for v,w in graph[u]:
#             nc = cost + w

#             if i <= 0:
#                 heapq.heappush(heap, (nc,i + 1,v))

#     return -1

def eccentricities(graph, vertices):
	ecc = []
	dist = floyd_warshall(graph, vertices)
	
	for u in dist:
		d = [dist[u][v] for v in dist[u] if dist[u][v] != INFINITY]
		if d: ecc.append(max(d))
		
	return ecc
	
def floyd_warshall(graph, vertices):
	dist = {}
	for u in vertices:
		dist[u] = {}
		for v in vertices:
			dist[u][v] = INFINITY
	
			
	for u in graph:
		dist[u][u] = 0
		for v in graph[u]:
			dist[u][v[0]] = v[1]
	
	for k in vertices:
		for i in vertices:
			for j in vertices:
			    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

	
	return dist


  
# MY SOLUTION = DIJKSTRA with at least 2 edges
n, e = list(map(int, input().split()))
graph = {}
for _ in range(e):
    u, v, w = list(map(int, input().split()))
    u -= 1 
    v -= 1
    
    if u in graph:
            graph[u] += [[v, w]]
    else:
            graph[u] = [[v, w]]

    if v in graph:
            graph[v] += [[u, w]]
    else:
            graph[v] = [[u, w]]

vertices = list(range(n))

INFINITY = 10**9
ecc = eccentricities(graph, vertices)
radius = min(ecc)
diameter = max(ecc)

print(diameter)





import numpy as np
import sys
import heapq
# class Graph(): 
  
#     def __init__(self, vertices): 
#         self.V = vertices 
#         self.graph = [[0 for column in range(vertices)]  
#                     for row in range(vertices)] 
  
#     def minDistance(self, dist, sptSet, src): 
#         min = sys.maxsize
#         min_index = -1
#         for v in range(self.V): 
#             if dist[v] < min and sptSet[v] == False : 
#                 min = dist[v] 
#                 min_index = v 
  
#         return min_index 

  
#     def dijkstra(self, src): 
        
#         # weights = self.graph[src]
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = 0 
#         #     self.graph[i][src] = 0
            
  
#         dist = [sys.maxsize] * self.V 
#         dist[src] = 0
#         sptSet = [False] * self.V 
  
#         for cout in range(self.V): 
#             u = self.minDistance(dist, sptSet, src) 
#             if u == -1 : continue
#             sptSet[u] = True
#             for v in range(self.V): 
#                 if self.graph[u][v] > 0 and sptSet[v] == False and dist[v] > dist[u] + self.graph[u][v]: 
#                     dist[v] = dist[u] + self.graph[u][v] 
                    
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = weights[i]
#         #     self.graph[i][src] = weights[i]
        
#         dist.remove(0)
#         MINIMUM = np.inf
#         for idx in range(len(dist)):
#             if idx != src and not self.graph[idx][src] and dist[idx] < MINIMUM : 
#                 MINIMUM = dist[idx]
            
#         return MINIMUM

# def findCheapestPrice(n, flights, src , dst ) : 
#     graph = {}

#     for u in range(n):
#         graph[u] = []

#     for u,v,w in flights:
#         graph[u].append((v,w))

#     heap = [(0,-n,src)]
    

#     while heap:
#         (cost,i,u) = heapq.heappop(heap)

#         if u == dst :
#             return cost
#             # if i >= n - 1 : continue
#             # else:  return cost
#             # if u not in list(zip(*graph[src]))[0] : return cost

#         for v,w in graph[u]:
#             nc = cost + w

#             if i <= 0:
#                 heapq.heappush(heap, (nc,i + 1,v))

#     return -1

def eccentricities(graph, vertices):
	ecc = []
	dist = floyd_warshall(graph, vertices)
	
	for u in dist:
		d = [dist[u][v] for v in dist[u] if dist[u][v] != INFINITY]
		if d: ecc.append(max(d))
		
	return ecc
	
def floyd_warshall(graph, vertices):
	dist = {}
	for u in vertices:
		dist[u] = {}
		for v in vertices:
			dist[u][v] = INFINITY
	
			
	for u in graph:
		dist[u][u] = 0
		for v in graph[u]:
			dist[u][v[0]] = v[1]
	
	for k in vertices:
		for i in vertices:
			for j in vertices:
			    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

	
	return dist


  
# MY SOLUTION = DIJKSTRA with at least 2 edges
n, e = list(map(int, input().split()))
graph = {}
for _ in range(e):
    u, v, w = list(map(int, input().split()))
    u -= 1 
    v -= 1
    
    if u in graph:
            graph[u] += [[v, w]]
    else:
            graph[u] = [[v, w]]

    if v in graph:
            graph[v] += [[u, w]]
    else:
            graph[v] = [[u, w]]

vertices = list(range(n))

INFINITY = 10**9
ecc = eccentricities(graph, vertices)
radius = min(ecc)
diameter = max(ecc)

print(diameter)





import numpy as np
import sys
import heapq
# class Graph(): 
  
#     def __init__(self, vertices): 
#         self.V = vertices 
#         self.graph = [[0 for column in range(vertices)]  
#                     for row in range(vertices)] 
  
#     def minDistance(self, dist, sptSet, src): 
#         min = sys.maxsize
#         min_index = -1
#         for v in range(self.V): 
#             if dist[v] < min and sptSet[v] == False : 
#                 min = dist[v] 
#                 min_index = v 
  
#         return min_index 

  
#     def dijkstra(self, src): 
        
#         # weights = self.graph[src]
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = 0 
#         #     self.graph[i][src] = 0
            
  
#         dist = [sys.maxsize] * self.V 
#         dist[src] = 0
#         sptSet = [False] * self.V 
  
#         for cout in range(self.V): 
#             u = self.minDistance(dist, sptSet, src) 
#             if u == -1 : continue
#             sptSet[u] = True
#             for v in range(self.V): 
#                 if self.graph[u][v] > 0 and sptSet[v] == False and dist[v] > dist[u] + self.graph[u][v]: 
#                     dist[v] = dist[u] + self.graph[u][v] 
                    
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = weights[i]
#         #     self.graph[i][src] = weights[i]
        
#         dist.remove(0)
#         MINIMUM = np.inf
#         for idx in range(len(dist)):
#             if idx != src and not self.graph[idx][src] and dist[idx] < MINIMUM : 
#                 MINIMUM = dist[idx]
            
#         return MINIMUM

# def findCheapestPrice(n, flights, src , dst ) : 
#     graph = {}

#     for u in range(n):
#         graph[u] = []

#     for u,v,w in flights:
#         graph[u].append((v,w))

#     heap = [(0,-n,src)]
    

#     while heap:
#         (cost,i,u) = heapq.heappop(heap)

#         if u == dst :
#             return cost
#             # if i >= n - 1 : continue
#             # else:  return cost
#             # if u not in list(zip(*graph[src]))[0] : return cost

#         for v,w in graph[u]:
#             nc = cost + w

#             if i <= 0:
#                 heapq.heappush(heap, (nc,i + 1,v))

#     return -1

def eccentricities(graph, vertices):
	ecc = []
	dist = floyd_warshall(graph, vertices)
	
	for u in dist:
		d = [dist[u][v] for v in dist[u] if dist[u][v] != INFINITY]
		if d: ecc.append(max(d))
		
	return ecc
	
def floyd_warshall(graph, vertices):
	dist = {}
	for u in vertices:
		dist[u] = {}
		for v in vertices:
			dist[u][v] = INFINITY
	
			
	for u in graph:
		dist[u][u] = 0
		for v in graph[u]:
			dist[u][v[0]] = v[1]
	
	for k in vertices:
		for i in vertices:
			for j in vertices:
				if dist[i][j] >= dist[i][k] + dist[k][j]:
					dist[i][j] = dist[i][k] + dist[k][j]
	
	return dist


  
# MY SOLUTION = DIJKSTRA with at least 2 edges
n, e = list(map(int, input().split()))
graph = {}
for _ in range(e):
    u, v, w = list(map(int, input().split()))
    u -= 1 
    v -= 1
    
    if u in graph:
            graph[u] += [[v, w]]
    else:
            graph[u] = [[v, w]]

    if v in graph:
            graph[v] += [[u, w]]
    else:
            graph[v] = [[u, w]]

vertices = list(range(n))

INFINITY = 100000
ecc = eccentricities(graph, vertices)
radius = min(ecc)
diameter = max(ecc)

print(diameter)





import numpy as np
import sys
import heapq
# class Graph(): 
  
#     def __init__(self, vertices): 
#         self.V = vertices 
#         self.graph = [[0 for column in range(vertices)]  
#                     for row in range(vertices)] 
  
#     def minDistance(self, dist, sptSet, src): 
#         min = sys.maxsize
#         min_index = -1
#         for v in range(self.V): 
#             if dist[v] < min and sptSet[v] == False : 
#                 min = dist[v] 
#                 min_index = v 
  
#         return min_index 

  
#     def dijkstra(self, src): 
        
#         # weights = self.graph[src]
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = 0 
#         #     self.graph[i][src] = 0
            
  
#         dist = [sys.maxsize] * self.V 
#         dist[src] = 0
#         sptSet = [False] * self.V 
  
#         for cout in range(self.V): 
#             u = self.minDistance(dist, sptSet, src) 
#             if u == -1 : continue
#             sptSet[u] = True
#             for v in range(self.V): 
#                 if self.graph[u][v] > 0 and sptSet[v] == False and dist[v] > dist[u] + self.graph[u][v]: 
#                     dist[v] = dist[u] + self.graph[u][v] 
                    
        
#         # for i in range(self.V) :
#         #     self.graph[src][i] = weights[i]
#         #     self.graph[i][src] = weights[i]
        
#         dist.remove(0)
#         MINIMUM = np.inf
#         for idx in range(len(dist)):
#             if idx != src and not self.graph[idx][src] and dist[idx] < MINIMUM : 
#                 MINIMUM = dist[idx]
            
#         return MINIMUM

# def findCheapestPrice(n, flights, src , dst ) : 
#     graph = {}

#     for u in range(n):
#         graph[u] = []

#     for u,v,w in flights:
#         graph[u].append((v,w))

#     heap = [(0,-n,src)]
    

#     while heap:
#         (cost,i,u) = heapq.heappop(heap)

#         if u == dst :
#             return cost
#             # if i >= n - 1 : continue
#             # else:  return cost
#             # if u not in list(zip(*graph[src]))[0] : return cost

#         for v,w in graph[u]:
#             nc = cost + w

#             if i <= 0:
#                 heapq.heappush(heap, (nc,i + 1,v))

#     return -1

def eccentricities(graph, vertices):
	ecc = []
	dist = floyd_warshall(graph, vertices)
	
	for u in dist:
		d = [dist[u][v] for v in dist[u] if dist[u][v] != INFINITY]
		if d: ecc.append(max(d))
		
	return ecc
	
def floyd_warshall(graph, vertices):
	dist = {}
	for u in vertices:
		dist[u] = {}
		for v in vertices:
			dist[u][v] = INFINITY
	
			
	for u in graph:
		dist[u][u] = 0
		for v in graph[u]:
			dist[u][v[0]] = v[1]
	
	for k in vertices:
		for i in vertices:
			for j in vertices:
				if dist[i][j] > dist[i][k] + dist[k][j]:
					dist[i][j] = dist[i][k] + dist[k][j]
	
	return dist


  
# MY SOLUTION = DIJKSTRA with at least 2 edges
n, e = list(map(int, input().split()))
graph = {}
for _ in range(e):
    u, v, w = list(map(int, input().split()))
    u -= 1 
    v -= 1
    
    if u in graph:
            graph[u] += [[v, w]]
    else:
            graph[u] = [[v, w]]

    if v in graph:
            graph[v] += [[u, w]]
    else:
            graph[v] = [[u, w]]

vertices = list(range(n))

INFINITY = 100000
ecc = eccentricities(graph, vertices)
radius = min(ecc)
diameter = max(ecc)

print(diameter)





# cook your dish here
MAX = 10**9
c, f = list(map(int, input().split()))
d = []
for i in range(c):
    d.append([-1 for j in range(c)])

for i in range(f):
    x, y, p = list(map(int, input().split()))
    d[x-1][y-1] = p
    d[y-1][x-1] = p

for i in range(c):
    for j in range(c):
        if i == j:
            d[i][j] = 0
        elif d[i][j] == -1:
            d[i][j] = MAX
for k in range(c):
    for i in range(c):
        for j in range(c):
            d[i][j] = min(d[i][j], (d[i][k] + d[k][j]))
p = 0
for i in range(c):
    for j in range(c):
        p = max(d[i][j], p)
print(p)


MAX = 999999
c, f = list(map(int, input().split()))
d = []
for i in range(c):
    d.append([-1 for j in range(c)] )

for i in range(f):
    x, y, p = list(map(int, input().split()))
    d[x-1][y-1] = p
    d[y-1][x-1] = p

for i in range(c):
    for j in range(c):
        if i == j:
            d[i][j] = 0
        elif d[i][j] == -1:
            d[i][j] = MAX

for w in range(c):
    for i in range(c):
        for j in range(c):
            d[i][j] = min(d[i][j], (d[i][w] + d[w][j]))

p = 0
for i in range(c):
    for j in range(c):
        p = max(d[i][j], p)

print(p)





MAX = 10**9
c, f = map(int, input().split())
d = []
for i in range(c):
    d.append([-1 for j in range(c)])

for i in range(f):
    x, y, p = map(int, input().split())
    d[x-1][y-1] = p
    d[y-1][x-1] = p

for i in range(c):
    for j in range(c):
        if i == j:
            d[i][j] = 0
        elif d[i][j] == -1:
            d[i][j] = MAX
for k in range(c):
    for i in range(c):
        for j in range(c):
            d[i][j] = min(d[i][j], (d[i][k] + d[k][j]))
p = 0
for i in range(c):
    for j in range(c):
        p = max(d[i][j], p)
print(p)

MAX = 10**5
c, f = map(int, input().split())
d = []
for i in range(c):
    d.append([-1 for j in range(c)])

for i in range(f):
    x, y, p = map(int, input().split())
    d[x-1][y-1] = p
    d[y-1][x-1] = p

for i in range(c):
    for j in range(c):
        if i == j:
            d[i][j] = 0
        elif d[i][j] == -1:
            d[i][j] = MAX
for k in range(c):
    for i in range(c):
        for j in range(c):
            d[i][j] = min(d[i][j], (d[i][k] + d[k][j]))
p = 0
for i in range(c):
    for j in range(c):
        p = max(d[i][j], p)
print(p)

try:
    MAX=10**9
    a, b=list(map(int, input().split()))
    c=[]
    for i in range(a):
     c.append([-1 for j in range(a)])
     
    for j in range(b):
     d, e, p=[int(i) for i in input().split()]
     c[d-1][e-1]=p
     c[e-1][d-1]=p
    for i in range(a):
     for j in range(a):
         if i==j:
            c[i][j]=0
         elif c[i][j] == -1:
            c[i][j]=MAX
    for k in range(a):
     for i in range(a):
        for j in range(a):
            c[i][j]=min(c[i][j], (c[i][k]+c[k][j]))

    p=0
    for i in range(a):
     for j in range(a):
        p=max(c[i][j], p)
    print(p)
except Exception:
    pass


# cook your dish here
MAX = 10**9
c, f = map(int, input().split())
g = []
for i in range(c):
    g.append([-1 for j in range(c)])

for i in range(f):
    x, y, p = map(int, input().split())
    g[x-1][y-1] = p
    g[y-1][x-1] = p

for i in range(c):
    for j in range(c):
        if i == j:
            g[i][j] = 0
        elif g[i][j] == -1:
            g[i][j] = MAX
for k in range(c):
    for i in range(c):
        for j in range(c):
            g[i][j] = min(g[i][j], (g[i][k] + g[k][j]))
p = 0
for i in range(c):
    for j in range(c):
        p = max(g[i][j], p)
print(p)

# cook your dish here
c, f = map(int, input().split())
dist=[[float('Inf') for _ in range(c)] for _ in range(c)]
for _ in range(f):
    u, v, p = map(int, input().split())
    u-=1 
    v-=1
    dist[u][v]=p 
    dist[v][u]=p 
for i in range(c):
    dist[i][i]=0
for k in range(c):
    for i in range(c):
        for j in range(c):
            if dist[i][j] > dist[i][k] + dist[k][j] :
                dist[i][j] = dist[i][k] + dist[k][j]
massimo=0
for i in range(c):
    massimo=max(massimo, max(dist[i]))
print(massimo)

a=input().split()
c,f=int(a[0]), int(a[1])
mindistance=[[float('inf') for i in range(c)] for i in range(c)]

for corner in range(c):
    mindistance[corner][corner]=0

for i in range(f):
    a=input().split()
    x, y, p = int(a[0])-1, int(a[1])-1, int(a[2])
    mindistance[x][y]=p
    mindistance[y][x]=p
    
for i in range(c):
    for j in range(c):
        for k in range(c):
            if mindistance[i][k]!=float('inf') and mindistance[j][i]!=float('inf'):
                if mindistance[j][k]>mindistance[j][i]+mindistance[i][k]:
                    mindistance[j][k]=mindistance[j][i]+mindistance[i][k]

mincost = -float('inf')
for i in mindistance:
    if mincost<max(i):
        mincost=max(i)
print(mincost)

def floyd_warshall(graph, N):
    dist = [[float('inf')] * (N + 1) for i in range(N + 1)]
    for u in graph:
        dist[u][u] = 0
        for v in graph[u]:
            dist[u][v] = graph[u][v]
    for k in range(1, N + 1):
        for i in range(1, N + 1):
            for j in range(1, N + 1):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist

def solve(C, F, cost):
    dist = floyd_warshall(cost, C)
    maximum = 0
    for i in range(1, C + 1):
        for j in range(1, C + 1):
            maximum = max(maximum, dist[i][j])
    return maximum

def __starting_point():
    C, F = list(map(int, input().strip().split()))
    cost = {i:{} for i in range(1, C + 1)}
    for flight in range(1, F + 1):
        x, y, p = list(map(int, input().strip().split()))
        cost[x][y] = p
        cost[y][x] = p
    print(solve(C, F, cost))

__starting_point()