Beispiel #1
0
 public void clear() {
   for (List<Edge> f : edges) {
     for (Edge e : f) {
       e.flow = 0;
     }
   }
 }
Beispiel #2
0
 int getPath(int v, int t, List<Edge> list, int cMin, boolean[] was) {
   if (v == t) {
     return cMin;
   }
   was[v] = true;
   for (Edge e : edges[v]) {
     if (was[e.to]) continue;
     if (e.flow > 0) {
       int got = getPath(e.to, t, list, Math.min(cMin, e.flow), was);
       if (got == 0) {
         continue;
       }
       list.add(e);
       e.flow -= got;
       return got;
     }
   }
   return 0;
 }
Beispiel #3
0
 public int dfs(int x, int target, int cMin) {
   if (x == target) {
     return cMin;
   }
   for (int i = cur[x]; i < edges[x].size(); cur[x] = ++i) {
     Edge e = edges[x].get(i);
     if (d[e.to] != d[x] + 1 || e.cap - e.flow == 0) {
       continue;
     }
     int add = dfs(e.to, target, Math.min(cMin, e.cap - e.flow));
     if (add == 0) {
       continue;
     }
     e.flow += add;
     e.rev.flow -= add;
     return add;
   }
   return 0;
 }