import sys import heapq def main(): input = sys.stdin.read().split() idx = 0 X = int(input[idx]); idx +=1 Y = int(input[idx]); idx +=1 N = int(input[idx]); idx +=1 postmen = [] for _ in range(N): x = int(input[idx]); idx +=1 y = int(input[idx]); idx +=1 v = int(input[idx]); idx +=1 postmen.append( (x, y, v) ) # Grid points (601 x 601) # Initialize the minimal time for each grid point INF = float('inf') otime = [ [ INF for _ in range(601) ] for _ in range(601) ] # Priority queue: (otime, x, y) heap = [] # Postman 1 is at (x1, y1) x1, y1, v1 = postmen[0] otime[x1][y1] = 0 heapq.heappush(heap, (0, x1, y1)) # Directions: up, down, left, right dirs = [ (-1,0), (1,0), (0,-1), (0,1) ] while heap: current_otime, x, y = heapq.heappop(heap) if current_otime > otime[x][y]: continue for dx, dy in dirs: nx = x + dx ny = y + dy if 1 <= nx <= 600 and 1 <= ny <= 600: # Find the minimal speed at (x,y) # Check if any postman is at (x,y) min_speed = 0 for px, py, pv in postmen: if px == x and py == y and pv > min_speed: min_speed = pv if min_speed == 0: # No postman here, cannot move continue # Calculate the time to move to (nx, ny) distance = 1000 # since it's adjacent time = distance / min_speed new_otime = current_otime + time if new_otime < otime[nx][ny]: otime[nx][ny] = new_otime heapq.heappush(heap, (new_otime, nx, ny)) # The answer is otime[X][Y] print("{0:.10f}".format(otime[X][Y])) if __name__ == '__main__': main()