1 条题解
-
0
参考答案:
#include<iostream> #include<cstring> using namespace std; const int N = 30010; int n, m, k; int dis[N], last[N]; struct Edge { int a, b, c; }edge[N]; int bellman_ford() { memset(dis, 0x3f, sizeof(dis)); dis[1] = 0; for (int i = 1; i <= k; ++i) { memcpy(last, dis, sizeof(dis)); for (int j = 1; j <= m; ++j) { auto t = edge[j]; dis[t.b] = min(dis[t.b], last[t.a] + t.c); } } return dis[n]; } int main() { cin >> n >> m >> k; for (int i = 1; i <= m; ++i) { cin >> edge[i].a >> edge[i].b >> edge[i].c; } if (bellman_ford() > 0x3f3f3f3f / 2) cout << "No path"; else cout << dis[n]; return 0; }
- 1
信息
- ID
- 97
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 4
- 已通过
- 1
- 上传者