Hi, I'm really new to Flow algorithms and I'm starting with maximum flow using the EdmondsKarp, I've implemented this version, for the test example extracted from SPOJ FASTFLOW the following test-case has a max-flow of 5, my code answers 3. what would be wrong ? Thanks
Test-Case:
4 6
1 2 3
2 3 4
3 1 2
2 2 5
3 4 3
4 3 3
int max_flow(int source, int sink) {
int residual[MAXN][MAXN]; memset(residual, 0, sizeof(residual));
while(1) {
int prev[MAXN]; memset(prev, -1, sizeof(prev));
int actual[MAXN]; memset(actual, 0, sizeof(actual));
prev[source] = source;
actual[source] = INF;
queue<int> q; q.push(source);
while(!q.empty()) {
int u = q.front(); q.pop();
for(int i = 0; i < graph[u].size(); i++) {
int v = graph[u][i];
if(capacity[u][v] - residual[u][v] > 0 && prev[v] == -1) {
prev[v] = u;
actual[v] = min(actual[u], capacity[u][v] - residual[u][v]);
if(v != sink) {
q.push(v);
} else {
while(prev[v] != v) {
u = prev[v];
residual[u][v] += actual[sink];
residual[v][u] -= actual[sink];
v = u;
}
goto end;
}
}
}
}
end:;
if(prev[sink] == -1) {
int sum = 0;
for(int i = 0; i < MAXN; i++) {
sum += residual[source][i];
}
return sum;
}
}
}