MLE 4个点
#include <bits/stdc++.h>
using namespace std;
struct node
{
int to, data;
};
struct node1
{
int now, step;
};
const int N = 1500 + 10;
int n, m, x, u, v, w, ans, maxn = INT_MIN;
vector<node> a[N];
void bfs(int st)
{
queue<node1> q;
q.push({st, 0});
while (!q.empty())
{
node1 f = q.front();
// cout << f.now << " " << f.step << endl;
// cout << q.size() << endl;
q.pop();
if (f.now == n)
{
maxn = max(maxn, f.step);
continue;
}
for (int i = 0; i < a[f.now].size(); i++)
{
// vis[a[f.now][i].to] = 1;
q.push({a[f.now][i].to, f.step + a[f.now][i].data});
}
}
return;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
cin >> u >> v >> w;
a[u].push_back({v, w});
}
bfs(1);
if (maxn == INT_MIN)
{
cout << -1 << endl;
return 0;
}
cout << maxn << endl;
return 0;
}