1 条题解
-
0
,floyd 方便好写
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; int n, m, s, t; int x[MAXN + 5], y[MAXN + 5]; double dis[MAXN + 5][MAXN + 5]; double len(int u, int v) { return sqrt((x[u] - x[v]) * (x[u] - x[v]) + (y[u] - y[v]) * (y[u] - y[v])); } signed main() { ios::sync_with_stdio(false); cin.tie(0); // 输入 cin >> n; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; cin >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dis[i][j] = 100 * 20000; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; dis[u][v] = min(dis[u][v], len(u, v)); dis[v][u] = dis[u][v]; } cin >> s >> t; // floyd for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); // 输出 cout << fixed << setprecision(2) << dis[s][t] << "\n"; return 0; }
- 1
信息
- ID
- 561
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- (无)
- 递交数
- 44
- 已通过
- 20
- 上传者