Skip to content

Self loop handling #1

Closed
Closed
@yosupo06

Description

@yosupo06

Reporter: Mi_Sawa (Japanese tweet: https://twitter.com/Mi_Sawa/status/1303170874938331137)

max_flow / min_cost_flow cannot handle self-loops "correctly".

This is the code of max_flow.add_edge(). We can notice that we cannot handle an id of reverse edge correctly.
In now, in spite of this code wrong, everything goes well. However, cleary we should fix this.

    int add_edge(int from, int to, Cap cap) {
        assert(0 <= from && from < _n);
        assert(0 <= to && to < _n);
        assert(0 <= cap);
        int m = int(pos.size());
        pos.push_back({from, int(g[from].size())});
        g[from].push_back(_edge{to, int(g[to].size()), cap});
        g[to].push_back(_edge{from, int(g[from].size()) - 1, 0});
        return m;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions