I have algorithm for finding maximum flow. Does it have an author or name?

85 Views Asked by At

I'm beginner in programming and I'm learning algorithms to find maximum flows.

Most of them are rather difficult such as Ford-Falkerson, Edmunds-Karp and Dinitz. The problem is here: https://cses.fi/problemset/task/1694

I found an algorithm that finds maximum flow just for one depth first search for O(n+m). What is the name or author of this algorithm? This solution uses just one DFS. All standard algorithms use many DFS or BFS searches, but not this. I'm a bit confused.

#include<bits/stdc++.h>
using namespace std;

vector<vector<pair<int, long long>>> adj;
vector<bool> visited;

long long dfs(int to) {
    long long r = 0;
    visited[to] = true;
    for (const auto& [from, flow]: adj[to]) {
        if (from == 1 || visited[from]) {
            r += flow;
        } else {
            r += min(flow, dfs(from));
        }
    }
    return r;
}

int main() {
    int n, m;
    cin >> n >> m;

    adj.resize(n + 1);
    visited.resize(n + 1, false);

    for (int i = 0; i < m; i++) {
        int from, to, flow;
        cin >> from >> to >> flow;
        adj[to].push_back({from, flow});
    }
    cout << dfs(n);
}

Can you help me to understand why Dinitz or Edmunds-Karp, with O(m2n) complexity, are needed?

1

There are 1 best solutions below

1
On

Breaks on the following graph since the second visit to v will incorrectly assume that there is one unit of flow available to pull:

There is an arc from the source to v with capacity one, and two arcs from v to the sink with capacity two.