POJ 2455 Secret Milking machine two points + maximum flow

Source: Internet
Author: User

Test instructions

For a graph, a path that does not intersect the T-bar Edge from point 1 to N, and the goal is to minimize the maximum edge in the T-path and output the maximum edge.

Analysis:

The problem of finding the most value satisfies monotonicity can be done by two points, and the second is an accelerated enumeration method. The two-point enumeration of the maximum edge build, each time with a length of less than or equal to two points of the edge of the map and the capacity of 1, the maximum flow can be.

Code:

POJ 2455//sep9#include <iostream> #include <queue> #include <algorithm>using namespace Std;const int Maxn=256;const int maxm=40012;struct edge{int v,f,nxt;} e[maxm*2+10];queue<int> que;int src,sink;int g[maxn+10];int nume;bool vis[maxn+10];int dist[maxN+10];int n,p,t; int a[maxm],b[maxm],c[maxm];void addedge (int u,int v,int c) {e[++nume].v=v;e[nume].f=c;e[nume].nxt=g[u];g[u]=nume;e[ ++nume].v=u;e[nume].f=c;e[nume].nxt=g[v];g[v]=nume;} void Init () {memset (g,0,sizeof (g)); nume=1;} int BFs () {while (!que.empty ()) Que.pop (); memset (dist,0,sizeof (Dist)); memset (vis,0,sizeof (Vis)); vis[src]=true; Que.push (SRC), while (!que.empty ()) {int U=que.front (), Que.pop (), for (int i=g[u];i;i=e[i].nxt) if (e[i].f&&! VIS[E[I].V]) {Que.push (E[I].V);d ist[e[i].v]=dist[u]+1;vis[e[i].v]=true; if (e[i].v==sink) return 1;}} return 0;} int dfs (int u,int delta) {if (U==sink) return delta;int ret=0;for (int i=g[u];ret<delta&&i;i=e[i].nxt) if (E[i] . f&&dist[e[i].v]==dist[u]+1) {int Dd=dfs (e[i].v,min(E[i].f,delta-ret)); if (dd>0) {e[i].f-=dd;e[i^1].f+=dd;ret+=dd;} Elsedist[e[i].v]=-1;} return ret;} int dinic () {int ret=0;while (BFS () ==1) Ret+=dfs (Src,int_max); return ret;} BOOL Check (int mid) {init (); src=0,sink=n+1;for (int i=0;i<p;++i) if (c[i]<=mid) Addedge (a[i],b[i],1); Addedge (src , 1,t); Addedge (n,sink,t); if (Dinic () ==t) return True;return false;} int main () {scanf ("%d%d%d", &n,&p,&t), int maxl=-1;for (int i=0;i<p;++i) {scanf ("%d%d%d", &a[i], &b[i],&c[i]); Maxl=max (Maxl,c[i]);} int L=0,r=maxl+1,ans;while (l<r) {int mid= (l+r)/2;if (check (mid)) r=mid,ans=mid;elsel=mid+1;}  printf ("%d", ans); return 0;}


POJ 2455 Secret Milking machine two points + maximum flow

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.