标签:
Description
Input
Output
Sample Input
5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1
Sample Output
6
Source
1 //It is made by jump~ 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #ifdef WIN32 13 #define OT "%I64d" 14 #else 15 #define OT "%lld" 16 #endif 17 using namespace std; 18 typedef long long LL; 19 const int inf = (1<<30); 20 const int MAXN = 500011; 21 const int MAXM = 500011; 22 int n; 23 int first[MAXN],next[MAXM],to[MAXM],w[MAXM]; 24 int dis[MAXN]; 25 bool pd[MAXN]; 26 int ecnt; 27 int Min,Max; 28 int ans; 29 queue<int>Q; 30 31 inline int getint() 32 { 33 int w=0,q=0; 34 char c=getchar(); 35 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar(); 36 if (c==‘-‘) q=1, c=getchar(); 37 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar(); 38 return q ? -w : w; 39 } 40 41 inline void Init(){ 42 ecnt=0; memset(first,0,sizeof(first)); 43 Max=0; Min=inf; 44 while(!Q.empty()) Q.pop(); 45 ans=0; 46 } 47 48 inline void link(int x,int y,int z){ 49 next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; w[ecnt]=z; 50 } 51 52 inline void spfa(){ 53 for(int i=0;i<=n;i++) dis[i]=-inf; 54 Q.push(Min); pd[Min]=1; dis[Min]=0; 55 while(!Q.empty()) { 56 int u=Q.front(); Q.pop(); pd[u]=0; 57 for(int i=first[u];i;i=next[i]) { //最长路 58 int v=to[i]; 59 if(dis[v]<dis[u]+w[i]) { 60 dis[v]=dis[u]+w[i]; 61 if(!pd[v]){ 62 Q.push(v); pd[v]=1; 63 } 64 } 65 } 66 } 67 ans=dis[Max]; 68 } 69 70 inline void solve(){ 71 while(scanf("%d",&n)!=EOF){ 72 Init(); 73 int x,y,z; 74 for(int i=1;i<=n;i++) { 75 x=getint()-1;y=getint();z=getint(); 76 link(x,y,z); 77 Min=min(Min,x); Max=max(Max,y); 78 } 79 for(int i=Min;i<Max;i++){//以前缀和为结点 80 link(i+1,i,-1); link(i,i+1,0);//要使所有点满足s[i+1]-s[i] <= 1 && s[i]-s[i+1] <= 0 81 } 82 spfa(); 83 printf("%d",ans); 84 } 85 } 86 87 int main() 88 { 89 solve(); 90 return 0; 91 }
---恢复内容结束---
---恢复内容结束---
标签:
原文地址:http://www.cnblogs.com/ljh2000-jump/p/5551357.html