#include <bits/stdc++.h>
using namespace std;
int t, c, ts, te, dist[2505], cnt[2505];
struct edge {
int v, w;
};
struct node {
int num, dis;
};
vector<vector<edge>> e;
queue<node> q;
void bfs(int s) {
cnt[s] = 1;
dist[s] = 0;
q.push({s, 0});
while (!q.empty()) {
node p = q.front();
q.pop();
cnt[p.num]++;
for (auto i: e[p.num]) {
if (cnt[i.v] < t - 1 && dist[i.v] > p.dis + i.w) {
dist[i.v] = p.dis + i.w;
q.push({i.v, dist[i.v]});
}
}
}
}
int main() {
memset(dist, 0x7f, sizeof(dist));
cin >> t >> c >> ts >> te;
e.resize(c + 5);
for (int i = 0; i < c; ++i) {
int rs, re, w;
cin >> rs >> re >> w;
e[rs].push_back({re, w});
e[re].push_back({rs, w});
}
bfs(ts);
cout << dist[te];
return 0;
}
这是用于解决 http://ybt.ssoier.cn:8088/problem_show.php?pid=1379 的程序,基本上是把dijkstra的优先队列换成了普通队列,我想问的主要有两点:
希望有大佬解答!谢谢!