mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 12:58:48 +00:00
853. 有边数限制的最短路
https://www.acwing.com/problem/content/submission/code_detail/6594231/
This commit is contained in:
parent
ed22c66a10
commit
d9969cbf64
34
AcWing/853/853.cpp
Normal file
34
AcWing/853/853.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
struct node {
|
||||||
|
int u, v, w;
|
||||||
|
} g[10005];
|
||||||
|
|
||||||
|
int n, m, k, dist[505], backup[505];
|
||||||
|
|
||||||
|
void bellman_ford() {
|
||||||
|
memset(dist, 0x3f, sizeof(dist));
|
||||||
|
dist[1] = 0;
|
||||||
|
for (int i = 1; i <= k; i++) {
|
||||||
|
memcpy(backup, dist, sizeof(dist));
|
||||||
|
for (int j = 1; j <= m; j++) {
|
||||||
|
dist[g[j].v] = min(dist[g[j].v], backup[g[j].u] + g[j].w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cin >> n >> m >> k;
|
||||||
|
for (int i = 1; i <= m; i++) {
|
||||||
|
cin >> g[i].u >> g[i].v >> g[i].w;
|
||||||
|
}
|
||||||
|
bellman_ford();
|
||||||
|
if (dist[n] > 0x1f1f1f1f) {
|
||||||
|
cout << "impossible" << endl;
|
||||||
|
} else {
|
||||||
|
cout << dist[n] << endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user