fn mcf_search(&self, s: usize, flow: &[i64], pot: &mut [i64]) -> Vec<Option<usize>> {
        let mut vis = vec![false; self.graph.num_v()];
        let mut dist = vec![INF; self.graph.num_v()];
        let mut par = vec![None; self.graph.num_v()];

        dist[s] = 0;
        while let Some(u) = (0..self.graph.num_v())
            .filter(|&u| !vis[u] && dist[u] < INF)
            .min_by_key(|&u| dist[u] - pot[u])
        {
            vis[u] = true;
            pot[u] = dist[u];
            for (e, v) in self.graph.adj_list(u) {
                if dist[v] > dist[u] + self.cost[e] && flow[e] < self.cap[e] {
                    dist[v] = dist[u] + self.cost[e];
                    par[v] = Some(e);
                }
            }
        }
        par
    }
// Maintains Johnson's potentials to prevent negative-weight residual edges.
// This enables running Dijkstra instead of the slower Bellman-Ford.
Maintains Johnson's potentials to prevent negative-weight residual edges.
This enables running Dijkstra instead of the slower Bellman-Ford.
Maintains Johnson ' s potentials to prevent negative - weight residual edges . This enables running Dijkstra instead of the slower Bellman - Ford .
fn mcf_search(&self, s: usize, flow: &[i64], pot: &mut [i64]) -> Vec<Option<usize>> {
        let mut vis = vec![false; self.graph.num_v()];
        let mut dist = vec![INF; self.graph.num_v()];
        let mut par = vec![None; self.graph.num_v()];
        dist[s] = 0;
        while let Some(u) = (0..self.graph.num_v())
            .filter(|&u| !vis[u] && dist[u] < INF)
            .min_by_key(|&u| dist[u] - pot[u])
        {
            vis[u] = true;
            pot[u] = dist[u];
            for (e, v) in self.graph.adj_list(u) {
                if dist[v] > dist[u] + self.cost[e] && flow[e] < self.cap[e] {
                    dist[v] = dist[u] + self.cost[e];
                    par[v] = Some(e);
                }
            }
        }
        par
    }
fn mcf_search ( & self , s : usize , flow : & [ i64 ] , pot : & mut [ i64 ] ) -> Vec < Option < usize > > { let mut vis = vec ! [ false self graph num_v ( ) ] ; let mut dist = vec ! [ INF self graph num_v ( ) ] ; let mut par = vec ! [ None self graph num_v ( ) ] ; dist [ s ] = 0 ; while let Some ( u ) = ( 0 .. self . graph . num_v ( ) ) . filter ( | & u | ! vis [ u ] && dist [ u ] < INF ) . min_by_key ( | & u | dist [ u ] - pot [ u ] ) { vis [ u ] = true ; pot [ u ] = dist [ u ] ; for ( e , v ) in self . graph . adj_list ( u ) { if dist [ v ] > dist [ u ] + self . cost [ e ] && flow [ e ] < self . cap [ e ] { dist [ v ] = dist [ u ] + self . cost [ e ] ; par [ v ] = Some ( e ) ; } } } par }
Maintains Johnson's potentials to prevent negative-weight residual edges.
Maintains Johnson ' s potentials to prevent negative - weight residual edges .
&self
s
usize
flow
&[i64]
pot
&mut [i64]
&self
s
usize
flow
&[i64]
pot
&mut [i64]