mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-01-11 16:31:58 +00:00
P3905 道路重建
R53624318
This commit is contained in:
parent
04c6d341b6
commit
8fd46c594a
@ -2,7 +2,25 @@
|
||||
|
||||
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() {
|
||||
cin >> n >> m;
|
||||
@ -19,16 +37,11 @@ int main() {
|
||||
cin >> d;
|
||||
for (int i = 1; i <= d; i++) {
|
||||
cin >> u >> v;
|
||||
g[u][v] = g[v][u] = f[u][v];
|
||||
}
|
||||
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]);
|
||||
}
|
||||
}
|
||||
g[u][v] = f[u][v];
|
||||
g[v][u] = f[v][u];
|
||||
}
|
||||
cin >> a >> b;
|
||||
cout << g[a][b] << endl;
|
||||
dijkstra();
|
||||
cout << dist[b] << endl;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user