mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-22 03:24:57 +08:00
refactor: change packages (#5430)
* refactor: change package * refactor: fix name --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
@ -1,57 +0,0 @@
|
||||
package com.thealgorithms.dynamicprogramming;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public final class FordFulkerson {
|
||||
private static final int INF = Integer.MAX_VALUE;
|
||||
|
||||
private FordFulkerson() {
|
||||
}
|
||||
|
||||
public static int networkFlow(int vertexCount, int[][] capacity, int[][] flow, int source, int sink) {
|
||||
int totalFlow = 0;
|
||||
|
||||
while (true) {
|
||||
int[] parent = new int[vertexCount];
|
||||
boolean[] visited = new boolean[vertexCount];
|
||||
Queue<Integer> queue = new LinkedList<>();
|
||||
|
||||
queue.add(source);
|
||||
visited[source] = true;
|
||||
parent[source] = -1;
|
||||
|
||||
while (!queue.isEmpty() && !visited[sink]) {
|
||||
int current = queue.poll();
|
||||
|
||||
for (int next = 0; next < vertexCount; next++) {
|
||||
if (!visited[next] && capacity[current][next] - flow[current][next] > 0) {
|
||||
queue.add(next);
|
||||
visited[next] = true;
|
||||
parent[next] = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!visited[sink]) {
|
||||
break; // No more augmenting paths
|
||||
}
|
||||
|
||||
int pathFlow = INF;
|
||||
for (int v = sink; v != source; v = parent[v]) {
|
||||
int u = parent[v];
|
||||
pathFlow = Math.min(pathFlow, capacity[u][v] - flow[u][v]);
|
||||
}
|
||||
|
||||
for (int v = sink; v != source; v = parent[v]) {
|
||||
int u = parent[v];
|
||||
flow[u][v] += pathFlow;
|
||||
flow[v][u] -= pathFlow;
|
||||
}
|
||||
|
||||
totalFlow += pathFlow;
|
||||
}
|
||||
|
||||
return totalFlow;
|
||||
}
|
||||
}
|
@ -5,8 +5,8 @@ package com.thealgorithms.dynamicprogramming;
|
||||
* supersequence of two given strings. The shortest supersequence is the smallest string
|
||||
* that contains both given strings as subsequences.
|
||||
*/
|
||||
final class ShortestCommonSuperSequenceLength {
|
||||
private ShortestCommonSuperSequenceLength() {
|
||||
final class ShortestCommonSupersequenceLength {
|
||||
private ShortestCommonSupersequenceLength() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user