@staticmethod defget_last_point(x1, y1, x2, y2, x3, y3): """給定矩形三頂點,求第四頂點。 利用畢氏定理找出直角頂點:直角頂點滿足其到另外兩點的 距離平方和等於另外兩點間的距離平方。知道直角頂點後, 第四點 = 對角線兩端和 - 直角頂點。 """ ab = dist2(x1, y1, x2, y2) ac = dist2(x1, y1, x3, y3) bc = dist2(x2, y2, x3, y3) if ab == ac + bc: # 點 3 是直角頂點(ab 為斜邊),點 1,2 是對角線兩端 return x1 + x2 - x3, y1 + y2 - y3 elif ac == ab + bc: # 點 2 是直角頂點(ac 為斜邊),點 1,3 是對角線兩端 return x1 + x3 - x2, y1 + y3 - y2 else: # bc == ab + ac # 點 1 是直角頂點(bc 為斜邊),點 2,3 是對角線兩端 return x2 + x3 - x1, y2 + y3 - y1
t = int(input()) # 測試資料組數
for _ inrange(t): n, price, A, B = map(int, input().split()) # n = S(城市數),price = t(航線單價) citys = [City(list(map(int, input().split()))) for _ inrange(n)]
m = n * 4# 總節點數 = 城市數 × 4 g = [[float('inf')] * m for _ inrange(m)]
# --- 建圖:城市內鐵路 --- for k, city inenumerate(citys): for i, p1 inenumerate(city.points): for j, p2 inenumerate(city.points): g[k * 4 + i][k * 4 + j] = dist(p1[0], p1[1], p2[0], p2[1]) * city.price
# --- 建圖:城市間航線 --- for i, city1 inenumerate(citys): for j, city2 inenumerate(citys): if i == j: continue for k1, p1 inenumerate(city1.points): for k2, p2 inenumerate(city2.points): g[i * 4 + k1][j * 4 + k2] = dist(p1[0], p1[1], p2[0], p2[1]) * price
# --- Floyd–Warshall 求全源最短路 --- for k inrange(m): for i inrange(m): if g[i][k] == float('inf'): continue# 跳過不可達的中繼點,常數優化 for j inrange(m): g[i][j] = min(g[i][j], g[i][k] + g[k][j])
# --- 取答案:枚舉起終點機場的 4×4 種配對 --- A -= 1 B -= 1 ans = float('inf') for i inrange(4): for j inrange(4): ans = min(ans, g[A * 4 + i][B * 4 + j]) print(f'{ans:.1f}')