使用SPFA但是莫名其妙WA73,大佬求助!!!
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1510,M=50010;
struct edge{
int to;
int d;
};
vector<edge> e[N];
void addedge(int u,int v,int w){
e[u].push_back((edge){v,w});
// e[v].push_back((edge){u,w});
}
int dist[N];
int n,m;
bool inque[N];
void init() {
for(int i=1;i<N;++i){
dist[i]=LLONG_MIN;
}
}
void input() {
cin>>n>>m;
for(int i=1;i<=m;++i){
int u,v,w;
cin>>u>>v>>w;
addedge(u,v,w);
}
}
void spfa() {
dist[1]=0;
inque[1]=1;
queue<int> q;
q.push(1);
while(!q.empty()) {
// cerr<<1<<"\n";
int p=q.front();
q.pop();
for(auto v:e[p]){
if(dist[v.to]<dist[p]+v.d){
dist[v.to]=dist[p]+v.d;
if(!inque[v.to]){
inque[v.to]=1;
q.push(v.to);
}
}
}
inque[p]=0;
}
}
void output(){
if(dist[n]==LLONG_MIN){
cout<<-1<<"\n";
}
else{
cout<<dist[n]<<"\n";
}
}
void solve() {
input();
spfa();
output();
}
signed main() {
solve();
return 0;
}