POJ 2455 Secret Milking Machine
Topic links
Test instructions: An no-map, requires that a T-bar does not repeat the road can go from 1 to T, ask the maximum side of the road the minimum value can be how much
Train of thought: two points + maximum flow, binary length, even edge, note is a graph, so the reverse edge is a capacity, then the source point and 1 even capacity t,n and sinks the capacity is T
Code:
#include <cstdio> #include <cstring> #include <queue> #include <algorithm>using namespace std; const int maxnode = 205;const int MAXEDGE = 100005;typedef int type;const Type INF = 0x3f3f3f3f;struct Edge {int u, v; Type cap, Flow; Edge () {}edge (int u, int v, type cap, type flow) {This->u = U;this->v = V;this->cap = Cap;this->flow = flow;} };struct dinic {int n, m, S, t; Edge edges[maxedge];int first[maxnode];int Next[maxedge];bool Vis[maxnode]; Type d[maxnode];int cur[maxnode];vector<int> cut;void init (int n) {this->n = N;memset (First,-1, sizeof (first)) ; m = 0;} void Add_edge (int u, int v, Type cap) {Edges[m] = Edge (U, V, cap, 0); Next[m] = first[u];first[u] = M++;edges[m] = Edge (V, U, cap, 0); Next[m] = first[v];first[v] = m++;} BOOL BFs () {memset (Vis, false, sizeof (VIS));queue<int> Q; Q.push (s);d [s] = 0;vis[s] = True;while (! Q.empty ()) {int u = q.front (); Q.pop (); for (int i = first[u]; I! = 1; i = Next[i]) {edge& e = edges[i];if (!VIS[E.V] && e.cap > E.flow) {vis[e.v] = true;d[e.v] = D[u] + 1; Q.push (E.V);}}} return vis[t];} Type DFS (int u, Type a) {if (U = = T | | a = = 0) return A; Type flow = 0, f;for (int &i = Cur[u]; i = 1; i = Next[i]) {edge& e = edges[i];if (D[u] + 1 = d[e.v] && (f = DFS (e.v, Min (A, e.cap-e.flow))) > 0) {e.flow + = F;edges[i^1].flow = F;flow + F;a = f;if (A = = 0) break;} return flow;} Type maxflow (int s, int t) {this->s = s; this->t = t; Type flow = 0;while (BFS ()) {for (int i = 0; i < n; i++) Cur[i] = First[i];flow + = DFS (s, INF);} return flow;} void Mincut () {cut.clear (); for (int i = 0; i < m; i + = 2) {if (vis[edges[i].u] &&!vis[edges[i].v]) Cut.push_bac K (i);}}} gao;const int n = 40005;int n, p, T;int u[n], V[n], w[n];bool judge (int len) {gao.init (n + 2); Gao.add_edge (0, 1, t); for (i NT i = 0; I < P; i++) {if (W[i] > Len) continue;gao.add_edge (U[i], v[i], 1);} Gao.add_edge (n, n + 1, t), return GAO. Maxflow (0, n + 1) = = t;} int main () {while (~SCANF ("%d%d%d ", &n, &p, &t)) {int L = 0, r = 0;for (int i = 0; i < P; i++) {scanf ("%d%d%d ", &u[i], &v[i], & ; w[i]); r = Max (R, W[i]);} while (L < r) {int mid = (L + R)/2;if (judge (mid)) R = Mid;else L = mid + 1;} printf ("%d\n", L);} return 0;}
POJ 2455 Secret Milking Machine (two points + maximum flow)