Skip to main content

SteinerTreeOutput

Struct SteinerTreeOutput 

Source
pub struct SteinerTreeOutput<'g, S, G, P = NoParent>{
    graph: &'g G,
    dp: Vec<<G as VertexMap<S::T>>::Vmap>,
    parent: Vec<P::State>,
}

Fields§

§graph: &'g G§dp: Vec<<G as VertexMap<S::T>>::Vmap>§parent: Vec<P::State>

Implementations§

Source§

impl<S, G, P> SteinerTreeOutput<'_, S, G, P>

Source

pub fn minimum_from_source(&self, source: G::Vertex) -> S::T

Examples found in repository?
crates/library_checker/src/graph/minimum_steiner_tree.rs (line 15)
5pub fn minimum_steiner_tree(reader: impl Read, writer: impl Write) {
6    prepare_io!(reader, writer);
7    sc!(n, m, (graph, weights): @UndirectedGraphScanner::<usize, u64>::new(n, m));
8    sc!(k, terminals: [usize; k]);
9    let tree = graph
10        .steiner_tree()
11        .with_standard_sp_additive()
12        .with_parent()
13        .solve(terminals[1..].iter().copied(), |eid| weights[eid]);
14    let edges = tree.edges_from_source(terminals[0]).unwrap();
15    pp!(tree.minimum_from_source(terminals[0]), edges.len(); @it edges);
16}
More examples
Hide additional examples
crates/competitive/src/graph/steiner_tree.rs (line 257)
253    pub fn edges_from_source(&self, source: G::Vertex) -> Option<Vec<G::Label>> {
254        if self.dp.is_empty() {
255            return Some(vec![]);
256        }
257        if self.minimum_from_source(source) == S::inf() {
258            return None;
259        }
260        let graph = self.graph;
261        let mut index = graph.construct_vmap(|| 0usize);
262        for (i, u) in graph.vertices().enumerate() {
263            *graph.vmap_get_mut(&mut index, u) = i;
264        }
265        let mut uf = UnionFind::new(graph.vsize());
266        let mut edges = vec![];
267        let mut stack = vec![(self.dp.len() - 1, source)];
268        while let Some((bit, u)) = stack.pop() {
269            match graph.vmap_get(&self.parent[bit], u) {
270                SteinerTreeParent::None => {}
271                &SteinerTreeParent::Split(sub) => {
272                    stack.push((sub, u));
273                    stack.push((bit ^ sub, u));
274                }
275                SteinerTreeParent::Edge(v, label) => {
276                    if uf.unite(*graph.vmap_get(&index, u), *graph.vmap_get(&index, *v)) {
277                        edges.push(label.clone());
278                    }
279                    stack.push((bit, *v));
280                }
281            }
282        }
283        Some(edges)
284    }
Source§

impl<S, G> SteinerTreeOutput<'_, S, G, RecordParent>

Source

pub fn edges_from_source(&self, source: G::Vertex) -> Option<Vec<G::Label>>

For undirected graphs with nonnegative additive weights. Returns None when the terminals cannot be connected to source.

Examples found in repository?
crates/library_checker/src/graph/minimum_steiner_tree.rs (line 14)
5pub fn minimum_steiner_tree(reader: impl Read, writer: impl Write) {
6    prepare_io!(reader, writer);
7    sc!(n, m, (graph, weights): @UndirectedGraphScanner::<usize, u64>::new(n, m));
8    sc!(k, terminals: [usize; k]);
9    let tree = graph
10        .steiner_tree()
11        .with_standard_sp_additive()
12        .with_parent()
13        .solve(terminals[1..].iter().copied(), |eid| weights[eid]);
14    let edges = tree.edges_from_source(terminals[0]).unwrap();
15    pp!(tree.minimum_from_source(terminals[0]), edges.len(); @it edges);
16}

Auto Trait Implementations§

§

impl<'g, S, G, P> Freeze for SteinerTreeOutput<'g, S, G, P>

§

impl<'g, S, G, P> RefUnwindSafe for SteinerTreeOutput<'g, S, G, P>

§

impl<'g, S, G, P> Send for SteinerTreeOutput<'g, S, G, P>

§

impl<'g, S, G, P> Sync for SteinerTreeOutput<'g, S, G, P>

§

impl<'g, S, G, P> Unpin for SteinerTreeOutput<'g, S, G, P>

§

impl<'g, S, G, P> UnsafeUnpin for SteinerTreeOutput<'g, S, G, P>

§

impl<'g, S, G, P> UnwindSafe for SteinerTreeOutput<'g, S, G, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToArrayVecScalar for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.