这题有负边权,我是怎么用dij过的?
# include <bits/stdc++.h>
# define old_six \
ios::sync_with_stdio (0);\
\
cin.tie (0);\
\
cout.tie (0);
# define ffor(i,name) \
for (auto i = name.begin (); i != name.end (); ++ i)
# define reg register
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll inf = -1e18;
struct node {
int id;
ll dis;
bool operator < (const node& x) const {
return dis > x.dis;
}
} ;
int n, m, a, b, c;
vector <pii> v[1005];
ll d[1505];
priority_queue <node> q;
ll dijkstra () {
fill (d + 2, d + n + 1, inf);
q.push ({1, 0});
while (! q.empty ()) {
node x = q.top ();
q.pop ();
if (x.dis < d[x.id])
continue ;
for (pii i : v[x.id])
if (d[x.id] + i.second > d[i.first]) {
d[i.first] = d[x.id] + i.second;
q.push ({i.first, d[i.first]});
}
}
return d[n] > inf ? d[n] : -1;
}
int main () {
old_six
cin >> n >> m;
while (m --) {
cin >> a >> b >> c;
v[a].push_back ({b, c});
}
cout << dijkstra ();
return 0;
}