poj 1201 Intervals( spfa + 差分约束)
2012-05-08 01:02
429 查看
首先感谢 y @ The Angry Teletubbies
http://www.cppblog.com/y346491470/articles/152876.html
某牛人的总结
/article/6250459.html
http://www.cppblog.com/y346491470/articles/152876.html
某牛人的总结
/article/6250459.html
#include<stdio.h> #include<stack> #include<string.h> #include<iostream> #include<algorithm> using namespace std; #define N 500005 #define inf 99999999 int head ,cost ,nxt ,pnt ,e; int dist ,vis ; void add(int u,int v,int c) { pnt[e]=v;cost[e]=c;nxt[e]=head[u];head[u]=e++; } int spfa(int s,int e) { for(int i=e;i<=s;i++) { dist[i]=-1;vis[i]=0; } dist[s]=0;vis[s]=1; int Q ,top=1;Q[0]=s; while(top) { int u=Q[--top];vis[u]=0; for(int i=head[u];i!=-1;i=nxt[i]) { int v=pnt[i]; if(dist[v]<dist[u]+cost[i]) { dist[v]=dist[u]+cost[i]; if(!vis[v]) { vis[v]=1; Q[top++]=v; } } } } return dist[e]; } int main() { int n;scanf("%d",&n); int l=inf,r=-1; memset(head,-1,sizeof(head)); e=0; while(n--) { int u,v,c; scanf("%d%d%d",&u,&v,&c); add(v,--u,c); l=min(l,u); r=max(r,v); } for(int i=l;i<r;i++) { add(i+1,i,0); add(i,i+1,-1); } cout<<spfa(r,l)<<endl; return 0; }
相关文章推荐
- POJ - 1201 Intervals 【差分约束 + 最长路模型】
- POJ 1201 Intervals(差分约束)
- poj 1201 Intervals(差分约束)
- POJ 1201 Intervals (差分约束)
- POJ1201-Intervals(差分约束)
- poj 1201 Intervals(差分约束)
- POJ 1201 Intervals【差分约束】
- POJ 1201 Intervals (区间差分约束)
- POJ 1201 Intervals (差分约束)
- poj 1201 Intervals(差分约束)
- poj 1201 Intervals(差分约束)
- poj 1201 Intervals 差分约束
- [POJ 1201]Intervals[差分约束]
- poj 1201 Intervals(差分约束)
- poj 1201 Intervals [差分约束]
- POJ 1201 Intervals(差分约束-spfa)
- POJ 1201 Intervals (差分约束,最短路)
- poj 1201 Intervals(第一道差分约束题)
- POJ 1201 Intervals [差分约束]
- POJ 1201 Intervals[差分约束]