标签:queue struct rom int mem 详细 span max for
详细解释待.
紫书模板:
struct Edge { int from, to, cap, flow; Edge (int u, int v, int c, int f) : from(u), to(v), cap(c), flow(f) { } }; struct EdmondsKarp { int n, m; vector<Edge> edges; vector<int> G[maxn]; int a[maxn]; int p[maxn]; void init(int n) { for (int i=0; i<n; ++i) G[i].clear(); edges.clear(); } void add(int u, int v , int val) { edges.push_back(Edge(u, v, val, 0)); edges.push_back(Edge(u, v, 0, 0)); m = edges.size(); G[u].push_back(m-2); G[v].push_back(m-1); } int Maxflow(int s, int t) { int flow = 0; while (1) { memset(a, 0, sizeof(a)); queue<int> Q; Q.push(s); a[s] = inf; while (!Q.empty()) { int x = Q.front(); Q.pop(); for (int i=0; i<G[x].size(); ++i) { Edge &e = edges[G[x][i]]; if (!a[e.to] && e.cap > e.flow) { p[e.to] = G[x][i]; a[e.to] = min(a[x], e.cap - e.flow); Q.push(e.to); } } if (a[t]) break; } if (!a[t]) break; for (int u = t; u!=s; u =edges[p[u]].from) { edges[p[u]].flow += a[t]; edges[p[u]^1].flow -= a[t]; } flow += a[t]; } return flow; } }Ek;
标签:queue struct rom int mem 详细 span max for
原文地址:https://www.cnblogs.com/cgjh/p/9497453.html