Struct EulerTourForVertex

Source
pub struct EulerTourForVertex<'a> {
    pub vidx: Vec<(usize, usize)>,
    /* private fields */
}

Fields§

§vidx: Vec<(usize, usize)>

Implementations§

Source§

impl<'a> EulerTourForVertex<'a>

Source

pub fn new(graph: &'a UndirectedSparseGraph) -> Self

Examples found in repository?
crates/library_checker/src/datastructure/vertex_add_subtree_sum.rs (line 15)
9pub fn vertex_add_subtree_sum(reader: impl Read, mut writer: impl Write) {
10    let s = read_all_unchecked(reader);
11    let mut scanner = Scanner::new(&s);
12    scan!(scanner, n, q, a: [u64; n], p: [usize]);
13    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
14    let graph = UndirectedSparseGraph::from_edges(n, edges);
15    let mut et = EulerTourForVertex::new(&graph);
16    et.subtree_vertex_tour(0, n);
17    let mut b = vec![0; n];
18    for i in 0..n {
19        b[et.vidx[i].0] = a[i];
20    }
21    let mut seg = SegmentTree::<AdditiveOperation<_>>::from_vec(b);
22    for _ in 0..q {
23        match scanner.scan::<usize>() {
24            0 => {
25                scan!(scanner, u, x: u64);
26                et.subtree_update(u, x, |k, x| seg.update(k, x));
27            }
28            1 => {
29                scan!(scanner, u);
30                writeln!(writer, "{}", et.subtree_query(u, |l, r| seg.fold(l..r))).ok();
31            }
32            _ => panic!("unknown query"),
33        }
34    }
35}
Source

pub fn length(&self) -> usize

Source

pub fn subtree_vertex_tour(&mut self, u: usize, p: usize)

Examples found in repository?
crates/competitive/src/tree/euler_tour.rs (line 63)
59    pub fn subtree_vertex_tour(&mut self, u: usize, p: usize) {
60        self.vidx[u].0 = self.vpos;
61        self.vpos += 1;
62        for a in self.graph.adjacencies(u).filter(|a| a.to != p) {
63            self.subtree_vertex_tour(a.to, u);
64        }
65        self.vidx[u].1 = self.vpos;
66    }
More examples
Hide additional examples
crates/library_checker/src/datastructure/vertex_add_subtree_sum.rs (line 16)
9pub fn vertex_add_subtree_sum(reader: impl Read, mut writer: impl Write) {
10    let s = read_all_unchecked(reader);
11    let mut scanner = Scanner::new(&s);
12    scan!(scanner, n, q, a: [u64; n], p: [usize]);
13    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
14    let graph = UndirectedSparseGraph::from_edges(n, edges);
15    let mut et = EulerTourForVertex::new(&graph);
16    et.subtree_vertex_tour(0, n);
17    let mut b = vec![0; n];
18    for i in 0..n {
19        b[et.vidx[i].0] = a[i];
20    }
21    let mut seg = SegmentTree::<AdditiveOperation<_>>::from_vec(b);
22    for _ in 0..q {
23        match scanner.scan::<usize>() {
24            0 => {
25                scan!(scanner, u, x: u64);
26                et.subtree_update(u, x, |k, x| seg.update(k, x));
27            }
28            1 => {
29                scan!(scanner, u);
30                writeln!(writer, "{}", et.subtree_query(u, |l, r| seg.fold(l..r))).ok();
31            }
32            _ => panic!("unknown query"),
33        }
34    }
35}
Source

pub fn path_vertex_tour(&mut self, u: usize, p: usize)

Examples found in repository?
crates/competitive/src/tree/euler_tour.rs (line 71)
67    pub fn path_vertex_tour(&mut self, u: usize, p: usize) {
68        self.vidx[u].0 = self.vpos;
69        self.vpos += 1;
70        for a in self.graph.adjacencies(u).filter(|a| a.to != p) {
71            self.path_vertex_tour(a.to, u);
72        }
73        self.vidx[u].1 = self.vpos;
74        self.vpos += 1;
75    }
Source

pub fn subtree_query<T, F: FnMut(usize, usize) -> T>(&self, u: usize, f: F) -> T

Examples found in repository?
crates/library_checker/src/datastructure/vertex_add_subtree_sum.rs (line 30)
9pub fn vertex_add_subtree_sum(reader: impl Read, mut writer: impl Write) {
10    let s = read_all_unchecked(reader);
11    let mut scanner = Scanner::new(&s);
12    scan!(scanner, n, q, a: [u64; n], p: [usize]);
13    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
14    let graph = UndirectedSparseGraph::from_edges(n, edges);
15    let mut et = EulerTourForVertex::new(&graph);
16    et.subtree_vertex_tour(0, n);
17    let mut b = vec![0; n];
18    for i in 0..n {
19        b[et.vidx[i].0] = a[i];
20    }
21    let mut seg = SegmentTree::<AdditiveOperation<_>>::from_vec(b);
22    for _ in 0..q {
23        match scanner.scan::<usize>() {
24            0 => {
25                scan!(scanner, u, x: u64);
26                et.subtree_update(u, x, |k, x| seg.update(k, x));
27            }
28            1 => {
29                scan!(scanner, u);
30                writeln!(writer, "{}", et.subtree_query(u, |l, r| seg.fold(l..r))).ok();
31            }
32            _ => panic!("unknown query"),
33        }
34    }
35}
Source

pub fn subtree_update<T, F: FnMut(usize, T)>(&self, u: usize, x: T, f: F)

Examples found in repository?
crates/library_checker/src/datastructure/vertex_add_subtree_sum.rs (line 26)
9pub fn vertex_add_subtree_sum(reader: impl Read, mut writer: impl Write) {
10    let s = read_all_unchecked(reader);
11    let mut scanner = Scanner::new(&s);
12    scan!(scanner, n, q, a: [u64; n], p: [usize]);
13    let edges = p.take(n - 1).enumerate().map(|(i, p)| (i + 1, p)).collect();
14    let graph = UndirectedSparseGraph::from_edges(n, edges);
15    let mut et = EulerTourForVertex::new(&graph);
16    et.subtree_vertex_tour(0, n);
17    let mut b = vec![0; n];
18    for i in 0..n {
19        b[et.vidx[i].0] = a[i];
20    }
21    let mut seg = SegmentTree::<AdditiveOperation<_>>::from_vec(b);
22    for _ in 0..q {
23        match scanner.scan::<usize>() {
24            0 => {
25                scan!(scanner, u, x: u64);
26                et.subtree_update(u, x, |k, x| seg.update(k, x));
27            }
28            1 => {
29                scan!(scanner, u);
30                writeln!(writer, "{}", et.subtree_query(u, |l, r| seg.fold(l..r))).ok();
31            }
32            _ => panic!("unknown query"),
33        }
34    }
35}
Source

pub fn path_query<T, F: FnMut(usize, usize) -> T>( &self, u: usize, v: usize, f: F, ) -> T

Source

pub fn path_update<T, F: FnMut(usize, T)>(&self, u: usize, x: T, invx: T, f: F)

Trait Implementations§

Source§

impl<'a> Clone for EulerTourForVertex<'a>

Source§

fn clone(&self) -> EulerTourForVertex<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for EulerTourForVertex<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for EulerTourForVertex<'a>

§

impl<'a> RefUnwindSafe for EulerTourForVertex<'a>

§

impl<'a> Send for EulerTourForVertex<'a>

§

impl<'a> Sync for EulerTourForVertex<'a>

§

impl<'a> Unpin for EulerTourForVertex<'a>

§

impl<'a> UnwindSafe for EulerTourForVertex<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.