0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-26 23:31:58 +00:00
OI-codes/Luogu/problem/P3905/P3905.cpp

48 lines
1.0 KiB
C++
Raw Normal View History

2021-07-19 11:44:55 +00:00
#include <bits/stdc++.h>
using namespace std;
2021-07-19 14:01:18 +00:00
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;
}
}
2021-07-19 11:44:55 +00:00
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
g[i][j] = f[i][j] = i == j ? 0 : 0x3f3f3f3f;
}
}
for (int i = 1; i <= m; i++) {
cin >> u >> v >> w;
f[u][v] = f[v][u] = w;
g[u][v] = g[v][u] = 0;
}
cin >> d;
for (int i = 1; i <= d; i++) {
cin >> u >> v;
2021-07-19 14:01:18 +00:00
g[u][v] = f[u][v];
g[v][u] = f[v][u];
2021-07-19 11:44:55 +00:00
}
cin >> a >> b;
2021-07-19 14:01:18 +00:00
dijkstra();
cout << dist[b] << endl;
2021-07-19 11:44:55 +00:00
return 0;
}