#include #include using namespace std; int N,M; int A[2525]; int a[5000],b[5000]; long c[5000]; long dist[2][2525]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>M; int now=0; for(int i=0;i>v; assert(1<=v&&v<=(long)1e9); A[i]=v; dist[now][i]=-1e18; } for(int i=0;i>u>>v>>w; assert(1<=u&&u<=N); assert(1<=v&&v<=N); //assert(1<=w&&w<=N); a[i]=u-1,b[i]=v-1,c[i]=w; } dist[now][0]=A[0]; for(int t=1;t<=3*N;t++) { int nxt=1-now; for(int i=0;i(long)-1e18) { dist[nxt][b[i]]=max(dist[nxt][b[i]],dist[now][a[i]]-c[i]+A[b[i]]); } bool fn=false; for(int i=0;i=2*N&&dist[now][N-1]