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>
impl<S, G, P> SteinerTreeOutput<'_, S, G, P>
Sourcepub fn minimum_from_source(&self, source: G::Vertex) -> S::T
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
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>
impl<S, G> SteinerTreeOutput<'_, S, G, RecordParent>
Sourcepub fn edges_from_source(&self, source: G::Vertex) -> Option<Vec<G::Label>>
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>where
&'g G: RefUnwindSafe,
Vec<<G as VertexMap<<S as ShortestPathSemiRing>::T>>::Vmap>: RefUnwindSafe,
Vec<<P as SteinerTreeParentPolicy<G>>::State>: RefUnwindSafe,
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>where
&'g G: UnsafeUnpin,
Vec<<G as VertexMap<<S as ShortestPathSemiRing>::T>>::Vmap>: UnsafeUnpin,
Vec<<P as SteinerTreeParentPolicy<G>>::State>: UnsafeUnpin,
impl<'g, S, G, P> UnwindSafe for SteinerTreeOutput<'g, S, G, P>where
&'g G: UnwindSafe,
Vec<<G as VertexMap<<S as ShortestPathSemiRing>::T>>::Vmap>: UnwindSafe,
Vec<<P as SteinerTreeParentPolicy<G>>::State>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more