#include<iostream> using namespace std; int n, m, s, t; const int N = 1e4+10, M = 9999999; int map[N][N]; int main() { cin >> n >> m >> s >> t; for (int i = 1;i <= n;i++) for (int j = 1;j <= n;j++) { if (i == j) map[i][j] = 0; else map[i][j] = M; } for (int i = 1;i <= m;i++) { int a, b, c; cin >> a >> b >> c; map[a][b] = min(c, map[a][b]); } for (int k = 1;k <= n;k++) for (int i = 1;i <= n;i++) for (int j = 1;j <= n;j++) { if (map[i][j] > map[i][k] + map[k][j]) map[i][j] = map[i][k] + map[k][j]; } cout << map[s][t] << endl; }哪里错了
时间: 2024-04-08 13:32:55 浏览: 144
使用include <iostream>时一定要加using namespace std
你的代码中有一个错误,即将 `map` 命名为 `map`,这是 C++ 中的关键字,会导致编译错误。为了避免这个问题,你可以将其命名为其他名称,比如 `graph`。另外,你需要在代码开头添加头文件 `<algorithm>` 来使用 `min` 函数。修改后的代码如下:
```cpp
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, s, t;
const int N = 1e4+10, M = 9999999;
int graph[N][N];
int main()
{
cin >> n >> m >> s >> t;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j)
graph[i][j] = 0;
else
graph[i][j] = M;
}
}
for (int i = 1; i <= m; i++) {
int a, b, c;
cin >> a >> b >> c;
graph[a][b] = min(c, graph[a][b]);
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (graph[i][j] > graph[i][k] + graph[k][j])
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
cout << graph[s][t] << endl;
return 0;
}
```
这样修改后,你的代码应该可以正确运行了。
阅读全文