AcWing 1129. 热浪
原题链接
简单
作者:
kermanrin
,
2024-10-17 14:23:10
,
所有人可见
,
阅读 2
#include <iostream>
#include <cstring>
using namespace std;
const int C = 6210;
const int T = 2510;
int m, t, b, e;
int g[T][T];
int dist[T];
bool st[T];
void dijkstra() {
memset(dist, 0x3f, sizeof dist);
memset(st, 0, sizeof st);
dist[b] = 0;
for (int i = 1 ; i <= t; i ++) {
int j = -1;
for (int k = 1; k <= t ;k ++) {
if(!st[k] && (j == -1 || dist[j] > dist[k])){
j = k;
}
}
st[j] = true;
for (int k = 1; k <= t ; k ++) {
dist[k] = min(dist[k], dist[j] + g[k][j]);
}
}
}
int main() {
cin >> t >> m >> b >> e;
memset(g, 0x3f, sizeof g);
for (int i = 1 ; i <= m ; i ++) {
int a, b, c;
cin >> a >> b >> c;
g[a][b] = g[b][a] = min(g[a][b], c);
}
dijkstra();
cout << dist[e] << endl;
return 0;
}