|
|
@ -57,6 +57,7 @@ public class Code03_DinicAlgorithm {
|
|
|
|
while (bfs(s, t)) {
|
|
|
|
while (bfs(s, t)) {
|
|
|
|
Arrays.fill(cur, 0);
|
|
|
|
Arrays.fill(cur, 0);
|
|
|
|
flow += dfs(s, t, Integer.MAX_VALUE);
|
|
|
|
flow += dfs(s, t, Integer.MAX_VALUE);
|
|
|
|
|
|
|
|
Arrays.fill(depth, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flow;
|
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -67,7 +68,6 @@ public class Code03_DinicAlgorithm {
|
|
|
|
boolean[] visited = new boolean[N];
|
|
|
|
boolean[] visited = new boolean[N];
|
|
|
|
visited[s] = true;
|
|
|
|
visited[s] = true;
|
|
|
|
while (!queue.isEmpty()) {
|
|
|
|
while (!queue.isEmpty()) {
|
|
|
|
// u是当前节点
|
|
|
|
|
|
|
|
int u = queue.pollLast();
|
|
|
|
int u = queue.pollLast();
|
|
|
|
for (int i = 0; i < nexts.get(u).size(); i++) {
|
|
|
|
for (int i = 0; i < nexts.get(u).size(); i++) {
|
|
|
|
Edge e = edges.get(nexts.get(u).get(i));
|
|
|
|
Edge e = edges.get(nexts.get(u).get(i));
|
|
|
@ -75,6 +75,9 @@ public class Code03_DinicAlgorithm {
|
|
|
|
if (!visited[v] && e.available > 0) {
|
|
|
|
if (!visited[v] && e.available > 0) {
|
|
|
|
visited[v] = true;
|
|
|
|
visited[v] = true;
|
|
|
|
depth[v] = depth[u] + 1;
|
|
|
|
depth[v] = depth[u] + 1;
|
|
|
|
|
|
|
|
if (v == t) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
queue.addFirst(v);
|
|
|
|
queue.addFirst(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -90,9 +93,6 @@ public class Code03_DinicAlgorithm {
|
|
|
|
if (s == t || r == 0) {
|
|
|
|
if (s == t || r == 0) {
|
|
|
|
return r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (depth[s] >= depth[t]) {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int f = 0;
|
|
|
|
int f = 0;
|
|
|
|
int flow = 0;
|
|
|
|
int flow = 0;
|
|
|
|
// s点从哪条边开始试 -> cur[s]
|
|
|
|
// s点从哪条边开始试 -> cur[s]
|
|
|
@ -112,7 +112,6 @@ public class Code03_DinicAlgorithm {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return flow;
|
|
|
|
return flow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
public static void main(String[] args) {
|
|
|
|