Poj 3169 Layout (difference constraint + Bellman)

Source: Internet
Author: User

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<
        

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.