I stuck to a problem Flawed flow
I do not understand how F[u]= 0 acyclic graphic guarantee in the approach below
I found a comment in the editorial But it is not very clear
how -> there's no vertex v that f[v]= 0 then we have a cycle in the graph, because each vertex of the graph has at least one incoming edge. (Consider the longest simple way in rest graph, we know that the top of the head in the path has an incoming edge and that the head of that edge is also in the path).
Please explain to someone what is the correct reason for the statement mentioned above?
The key element to solving the task is the following observation: if we all know the incoming edges of a vertex, all the remaining edges must be outgoing. The source does not have incoming fronts, so we already know that all of its fronts are outgoing. For all other peaks except the well, the amount of outflow and outflow is the same and equal to half the sum of the flow along its incident edges. The algorithm then consists of repeatedly directing the entire flow from the vertices for which all incoming fronts are known. This can be done with a single BFS:
for all v from 2 to n-1 F[v] : = sum (flux (v, u)) / 2; put the source in a queue as long as the queue is not empty v: = pop (queue) for all edges (v, u) if (v, u) is not yet directed direct v -> u F[u] = f[u] - flow (v, u) if you do not run and f[u] = 0 push (queue, u)
Since the stream contains no cycles, we can sort the vertices topologically. then
until all the edge directions are known, we can at least set the first vertex with unknown edges in the queue, as all its incoming edges will come from vertices of the vertex. lower cues, but we took the first top with unknown. edges.
Time: O (n + m)
Memory: O (n + m)
Implementation: c ++