pub struct Rerooting<T, M, FE, FV>where
    T: Clone,
    M: Fn(&T, &T) -> T,
    FE: Fn(&T, usize) -> T,
    FV: Fn(&T, usize) -> T,{
    pub dp: Vec<Vec<T>>,
    pub ans: Vec<T>,
    pub G: Vec<Vec<usize>>,
    pub edge_id: HashMap<(usize, usize), (usize, usize)>,
    /* private fields */
}
Expand description

全方位木DP

Fields§

§dp: Vec<Vec<T>>

dpテーブル

§ans: Vec<T>

結果を保存する配列

§G: Vec<Vec<usize>>

グラフ

§edge_id: HashMap<(usize, usize), (usize, usize)>

辺の番号: (u, v) -> (辺番号, G[u].index(v))

Implementations§

source§

impl<T, M, FE, FV> Rerooting<T, M, FE, FV>where T: Clone, M: Fn(&T, &T) -> T, FE: Fn(&T, usize) -> T, FV: Fn(&T, usize) -> T,

source

pub fn new(N: usize, id: T, merge: M, put_edge: FE, put_vertex: FV) -> Self

木を初期化する

  • 時間計算量: $O(N)$

引数

  • N: 頂点数
  • id: 単位元
  • merge: 値をマージする関数
  • put_edge: 辺を追加する関数
  • put_vertex: 頂点を追加する関数
source

pub fn add_edge(&mut self, u: usize, v: usize)

有向辺 (u,v) を追加する

  • 時間計算量: $O(1)$
source

pub fn add_edge2(&mut self, u: usize, v: usize)

有向辺 (u,v) / (v,u) を追加する

  • 時間計算量: $O(1)$
source

pub fn build(&mut self)

すべての頂点vについて,vを根として集約した値を求める

  • 時間計算量: $O(N)$
source

pub fn aggregate(&mut self, p: usize, u: usize) -> T

頂点uに対して値を集約する

  • 時間計算量: $O(N)$
source

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

rerootingを行う

  • 時間計算量: $O(N)$

引数

  • p: 親の頂点
  • u: 現在の頂点

Auto Trait Implementations§

§

impl<T, M, FE, FV> RefUnwindSafe for Rerooting<T, M, FE, FV>where FE: RefUnwindSafe, FV: RefUnwindSafe, M: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, M, FE, FV> Send for Rerooting<T, M, FE, FV>where FE: Send, FV: Send, M: Send, T: Send,

§

impl<T, M, FE, FV> Sync for Rerooting<T, M, FE, FV>where FE: Sync, FV: Sync, M: Sync, T: Sync,

§

impl<T, M, FE, FV> Unpin for Rerooting<T, M, FE, FV>where FE: Unpin, FV: Unpin, M: Unpin, T: Unpin,

§

impl<T, M, FE, FV> UnwindSafe for Rerooting<T, M, FE, FV>where FE: UnwindSafe, FV: UnwindSafe, M: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V