标签:des style http color os io strong for ar
解题报告
思路:
解方程组:
(a-1)-b<-c
0<=i-(i-1)<=1
Max-Min>=m
源点为Max,求出dis[Max]-dis[Min]
#include <iostream> #include <cstring> #include <cstdio> #include <deque> #include <stack> #define N 100001 #define M 550000 #define inf 0x3f3f3f3f using namespace std; int head[N],dis[N],vis[N]; int cnt,n,m; int maxx=0,minn=inf; struct node { int v,w,next; } edge[M]; void add(int u,int v,int w) { edge[cnt].v=v,edge[cnt].w=w; edge[cnt].next=head[u],head[u]=cnt++; } void SF() { stack<int>Q; memset(dis,inf,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[maxx]=0,vis[maxx]=1; Q.push(maxx); while(!Q.empty()) { int u=Q.top(); Q.pop(); vis[u]=0; for(int i=head[u]; i!=-1; i=edge[i].next) { int v=edge[i].v; if(dis[v]>dis[u]+edge[i].w) { dis[v]=dis[u]+edge[i].w; if(!vis[v]) { vis[v]=1; Q.push(v); } } } } } int main() { int i,j,u,v,w; while(~scanf("%d",&n)) { cnt=0; memset(head,-1,sizeof(head)); for(i=1; i<=n; i++) { scanf("%d%d%d",&u,&v,&w); if(v>maxx) maxx=v; if(u<minn) minn=u; add(v,u-1, -w); } for(i=1; i<=maxx; i++) { add(i-1,i,1); add(i,i-1,0); } SF(); printf("%d\n",dis[maxx]-dis[minn-1]); } return 0; }
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 21736 | Accepted: 8180 |
Description
Input
Output
Sample Input
5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1
Sample Output
6
标签:des style http color os io strong for ar
原文地址:http://blog.csdn.net/juncoder/article/details/38762053