0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2025-01-11 21:51:59 +00:00

P3905 道路重建

R53624318
This commit is contained in:
Baoshuo Ren 2021-07-19 22:01:18 +08:00 committed by Baoshuo Ren
parent 04c6d341b6
commit 8fd46c594a
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -2,7 +2,25 @@
using namespace std; using namespace std;
int n, m, u, v, w, d, a, b, f[105][105], g[105][105]; int n, m, u, v, w, d, a, b, f[105][105], g[105][105], dist[105];
bool st[105];
void dijkstra() {
memset(dist, 0x3f, sizeof(dist));
dist[a] = 0;
for (int i = 1; i < n; i++) {
int t = -1;
for (int j = 1; j <= n; j++) {
if (!st[j] && (t == -1 || dist[t] > dist[j])) {
t = j;
}
}
for (int j = 1; j <= n; j++) {
dist[j] = min(dist[j], dist[t] + g[t][j]);
}
st[t] = true;
}
}
int main() { int main() {
cin >> n >> m; cin >> n >> m;
@ -19,16 +37,11 @@ int main() {
cin >> d; cin >> d;
for (int i = 1; i <= d; i++) { for (int i = 1; i <= d; i++) {
cin >> u >> v; cin >> u >> v;
g[u][v] = g[v][u] = f[u][v]; g[u][v] = f[u][v];
} g[v][u] = f[v][u];
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
} }
cin >> a >> b; cin >> a >> b;
cout << g[a][b] << endl; dijkstra();
cout << dist[b] << endl;
return 0; return 0;
} }