Secret Milking Machine
Time Limit: 1000MS 

Memory Limit: 65536K 
Total Submissions: 10620 

Accepted: 3110 
Description
Farmer John is constructing a new milking, and wishes to keep it secret as long as possible. He has hidden in it deep within his farm and needs to is able to get to the machine without being detected. He must make a total of T (1 <= t <=) trips to the machine during its construction. He has a secret tunnel, that he uses, only for the return trips.
The farm comprises N (2 <= n <=) landmarks (numbered 1..N) connected by P (1 <= P <= 40,000) bidirectional Trails (numbered 1..P) and with a positive length this does not exceed 1,000,000. Multiple trails might join a pair of landmarks.
To minimize him chances of detection, FJ knows he cannot use any trail in the farm more than once and that he should try T o Use the shortest trails.
Help FJ get from the Barn (landmark 1) to the Secret milking machine (landmark N) a total of T times. Find the minimum possible length of the longest single trail that he'll have to use, subject to the constraint that he u Se No trail more than once. (Note well:the goal is to minimize the length of the longest trail and not the sum of the trail lengths.)
It is guaranteed this FJ can make all T trips without reusing a trail.
Input
* Line 1:three spaceseparated integers:n, P, and T
* Lines 2..p+1:line i+1 contains three spaceseparated integers, a_i, b_i, and l_i, indicating that A trail connects land Mark A_i to landmark b_i with length l_i.
Output
* Line 1: A single integer which is the minimum possible length of the longest segment of the Farmer John ' s route.
Sample Input
7 9 21 2 22 3 53 7 51 4 14 3 14 5 75 7 11 6 36 7 3
Sample Output
5
Hint
Farmer John can travel trails 1237 and 167. None of the trails travelled exceeds 5 units in length. It is impossible for Farmer John to travel from 1 to 7 twice without using at least one trail of length 5.
Huge input data,scanf is recommended.
Long time No 1 a ...
Test Instructions: gives you an npoint (numbered from 1 to N) and Mbars without a graph and weights for each edge. Requires at least a path from 1 to n that does not duplicate the Tbar, allowing you to find the minimum value of the maximum edge value on all paths (of course, the chosen ones, not the chosen ones), in order to satisfy this premise. the topic guarantees that from 1 to n there will be at least one path that is not duplicated on the Tbar, i.e. the problem must be solved.
Idea: Twominute enumeration of the minimum value of the maximum edge weight on all selected paths, mid, to determine if there are at least one path where the Tedge is not duplicated at the limit of the mid value from 1 to N.
The number of paths that are not duplicated by the edge can be solved with the maximum flowenumerating all the nonforward edges in the original, and if the edge is not greater than mid, the edge is added to the new graph and the edge capacity is 1. Finally, run the maximum stream from 1 to N.
AC Code:
#include <cstdio> #include <cstring> #include <queue> #include <stack> #include <vector># Include <algorithm> #define MAXN 200+10#define maxm 1600000+10#define INF 0x3f3f3f3fusing namespace Std;struct Edge {int from, to, cap, flow, next;}; Edge EDGE[MAXM], Redge[maxm];int HEAD[MAXN], Edgenum, RHEAD[MAXN], Redgenum;int DIST[MAXN], Cur[maxn];bool Vis[MAXN]; int N, M, t;struct node{int from, to, Val, next;}; Node Node[maxm];int HEAD[MAXN], nodenum;void addNode (int u, int v, int w) {node E = {u, V, W, Head[u]}; Node[nodenum] = E; Head[u] = nodenum++;} int max;//record maximum edge right void input () {memset (head,1, sizeof (head)); Nodenum = 0; Max = 0; int A, b, C; for (int i = 1; I <= M; i++) {scanf ("%d%d%d", &a, &b, &c); max = max (max, c);//Update AddNode (A, B, c); AddNode (b, A, c); }}void init () {edgenum = 0; Memset (Head,1, sizeof (head));} void Addedge (int u, int v, int w) {Edge E1 = {u, V, W, 0, Head[u]}; Edge[edgenum] = E1; Head[u] = edgenum++; Edge E2 = {V, u, 0, 0, Head[v]}; Edge[edgenum] = E2; HEAD[V] = edgenum++;} void Getmap (int mid) {for (int i = 0; i < Nodenum; i++) {if (Node[i].val <= mid)//less than or equal to limit add Edge (Node[i].from, node[i].to, 1);//Add New figure}}bool BFS (int s, int t) {queue<int> Q; memset (Dist,1, sizeof (Dist)); Memset (Vis, false, sizeof (VIS)); Dist[s] = 0; Vis[s] = true; Q.push (s); while (! Q.empty ()) {int u = q.front (); Q.pop (); for (int i = head[u]; i =1; i = Edge[i].next) {Edge E = Edge[i]; if (!vis[e.to] && e.cap > E.flow) {dist[e.to] = Dist[u] + 1; Vis[e.to] = true; if (e.to = = t) return true; Q.push (e.to); }}} return false;} int DFS (int x, int a, int t) {if (x = = T   a = = 0) return A; int flow = 0, F; for (int &i = CUR[X]; I! =1; i = Edge[i].next) {Edge &e = Edge[i]; if (dist[e.to] = = Dist[x] + 1 && (f = DFS (e.to, Min (A, e.cape.flow), T)) > 0) {edge[i].flow + = f; Edge[i^1].flow= f; Flow + + F; A= f; if (a = = 0) break; }} return flow;} int Maxflow (int s, int t) {int flow = 0; while (BFS (s, t)) {memcpy (cur, head, sizeof (head)); Flow + = DFS (s, INF, T); } return flow;} int main () {while (scanf ("%d%d%d", &n, &m, &t)! = EOF) {input (); int left = 0, right = max, ans = max; while (right >= left)//binary Find {int mid = (left + right) >> 1; Init (); Getmap (mid); if (Maxflow (1, N) >= T)//Determine if there is a path for Tbar not repeating {ans = min (ans, mid);//Update right = Mid 1; } else left = mid + 1; } printf ("%d\n", ans); } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
POJ 2455 Secret Milking Machine "two points + maximum flow" "1 to n nonrepeating path not less than T bar, the minimum value of the maximum edge weight value on the selected path is obtained"