因为数组大小debug了好久...因为i+1,所以最后要返回50001
#include<vector> #include<cstdio> #include<iostream> #include<cmath> #include<queue> #include<cstdlib> #include<cstring> #define numm ch-48 #define pd putchar(' ') #define pn putchar(' ') #define pb push_back #define fi first #define se second #define fre1 freopen("1.txt","r",stdin) #define fre2 freopen("2.txt","w",stdout) using namespace std; template <typename T> void read(T &res) { bool flag=false;char ch; while(!isdigit(ch=getchar())) (ch=='-')&&(flag=true); for(res=numm;isdigit(ch=getchar());res=(res<<1)+(res<<3)+numm); flag&&(res=-res); } template <typename T> void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } const int maxm=8000010; const int maxn=50005; const int inf=0x3f3f3f3f; const int INF=0x7fffffff; typedef long long ll; bool vis[maxn]; struct node { int to,net,w; }e[maxn*3]; int cnt,dis[maxn],head[maxn]; queue<int>que; void add(int u,int v,int w) { e[cnt].to=v; e[cnt].w=w; e[cnt].net=head[u]; head[u]=cnt++; } int spfa() { memset(dis,192,sizeof(dis)); dis[0]=0; que.push(0); vis[0]=true; while(!que.empty()) { int k=que.front(); que.pop(); vis[k]=false; for(int i=head[k];i!=-1;i=e[i].net) { int v=e[i].to; if(dis[k]+e[i].w>dis[v]) { dis[v]=dis[k]+e[i].w; if(!vis[v]) { que.push(v); vis[v]=true; } } } } return dis[50001]; } int main() { memset(head,-1,sizeof(head)); int m; for(int i=0;i<=50000;i++) add(i,i+1,0),add(i+1,i,-1); read(m); for(int i=1;i<=m;i++) { int u,v,w; read(u),read(v),read(w); add(u,v+1,w); } write(spfa());pn; return 0; } ///差分约束: //1.t[i+1]-t[i]>=0 ->i到i+1建0边 //2.t[i]-t[i+1]>=-1 ->i+1到i建-1边 //3.t[b+1]-t[a]>=c ->a到b+1建C边