UVA11478 halum [differential constraint system]

Source: Internet
Author: User

https://vjudge.net/problem/UVA-11478

Given a graph, each edge has a weighted value. Each time you can select a node v and an integer d, reduce the weight of all edges at the end of the V by D, increase the weight of all edges starting at V by D, and finally let the minimum value of all edges be greater than 0 and as large as possible.

Damn, the book was wrong. >0 not nonnegative wa several times because of this

Considering the constraints of each edge, Di represents the Halum amount of I

W-dv+du>0

Dv-du<w

However, solving this differential constraint system only makes this set of inequalities, the longest and shortest-path control is the maximum value of a single d rather than the minimum value

How is the minimum maximum?

Two-point answer ...

Then the inequality becomes dv-du<w-mid, which means that after operation the right can be larger than mid

No solution is mid=1, unbounded words is mid= maximum Benquan (can not use 1e9, overflow) is also established

#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespaceStd;typedefLong Longll;Const intn=505, m=3005, inf=1e9;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intn,m,u,v,w;structedge{intV,ne; DoubleW;} E[M];intH[n],cnt=0; inlinevoidInsintUintVintW) {CNT++; E[CNT].V=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=CNT;}intQ[n],head,tail,inq[n],num[n],d[n];inlinevoidLopint&AMP;X) {if(x==n) x=1;Else if(x==0) x=n-1;}BOOLSPFA (intmid) {Head=tail=1; memset (INQ,0,sizeof(INQ)); memset (num,0,sizeof(num));  for(intI=1; i<=n;i++) q[tail++]=i,inq[i]=1, d[i]=0;  while(head!=tail) {        intu=q[head++];inq[u]=0; Lop (head);  for(intI=h[u];i;i=e[i].ne) {            intv=e[i].v,w=e[i].w-mid; if(d[v]>d[u]+W) {D[v]=d[u]+W; if(!Inq[v]) {Inq[v]=1; if(++num[v]>n)return true; if(D[v]<d[q[head]]) head--, Lop (head), q[head]=v; Elseq[tail++]=v,lop (tail); }            }        }    }    return false;}intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) {CNT=0; Memset (H,0,sizeof(h)); intL=1, r=0, ans=0;  for(intI=1; i<=m;i++) U=read (), V=read (), W=read (), Ins (u,v,w), r=Max (R,W); if(SPFA (L)) {Puts ("No Solution");Continue;} Else if(!SPFA (R)) {Puts ("Infinite");Continue;} Else{             while(l<=R) {                intMid= (l+r) >>1; if(!SPFA (mid)) ans=mid,l=mid+1; Elser=mid-1; } printf ("%d\n", ans); }    }}

UVA11478 Halum [differential constrained system]

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.