Poj 3169 Layout (difference constraint + Bellman)
Question: Input N, ML, MD, N indicates that there are N cows in A row of 1-N. ML indicates that there are ML rows. Input A, B, D indicates that the farthest interval between A ox and B ox is D. MD indicates that there are MD rows. Input A, B, and D in each row indicates that A ox and B are separated by D, calculate the maximum interval of 1-n that satisfies all the conditions.
Relatively simple difference constraint, question A of this week's weekly Competition
#include
#include
#include
#include
#include
#include
#include const int N = 210;const int maxn = 1010;const int maxm = 21000;#define FOR(i,a,b) for(int i=a;i
dis[edge[j].u] + edge[j].w) { dis[edge[j].v] = dis[edge[j].u] + edge[j].w; flag = 1; } } if(!flag) break; } if(flag==1) return -1; else if(dis[t]==INF) return -2; else return dis[t];}int main(){ int u,v,w,a,b; while(scanf(%d%d%d,&n,&a,&b)!=EOF) { cnt=0; FOR(i,0,a) { scanf(%d%d%d,&u,&v,&w); add(u,v,w); } FOR(i,0,b) { scanf(%d%d%d,&u,&v,&w); add(v,u,-w); } int ans = Bellman(1,n); cout<