Files
python/TangDou/Topic/SSL1613.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

44 lines
1.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
int o(int t) {
return t * t;
}
const int N = 110;
int n, m, x[N], y[N];
double g[N][N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
// double类型的数组初始化不能用memset!!!!
// memset(g, 0x3f, sizeof g);
// for (int i = 0; i <= n; i++) g[i][i] = 0;
// 需要用二重循环进行初始化
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
if (i == j)
g[i][j] = 0;
else
g[i][j] = 0x3f3f3f3f;
}
cin >> m;
int l, r;
while (m--) {
cin >> l >> r;
g[r][l] = g[l][r] = sqrt((double)o(x[l] - x[r]) + (double)o(y[l] - y[r])); // 勾股定理
}
// floyd
for (int k = 1; k <= n; k++)
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (g[i][j] > g[i][k] + g[k][j]) g[i][j] = g[i][k] + g[k][j];
cin >> l >> r;
printf("%.2lf", g[l][r]);
return 0;
}