在学习支配树之前,请保证已经会写lca(tarian求法)
简介
支配树是什么?支配树能干什么?
- 对于一个DAG" role="presentation" style="position: relative;">DAGDAG上的每个点w" role="presentation" style="position: relative;">ww,都存在点d" role="presentation" style="position: relative;">dd满足去掉d" role="presentation" style="position: relative;">dd之后起点无法到达w" role="presentation" style="position: relative;">ww,我们称作d" role="presentation" style="position: relative;">dd支配w" role="presentation" style="position: relative;">ww,d" role="presentation" style="position: relative;">dd是w" role="presentation" style="position: relative;">ww的一个支配点。T" role="presentation" style="position: relative;">TT中节点u" role="presentation" style="position: relative;">uu是u" role="presentation" style="position: relative;">uu子树中所有节点的支配点(必经点),
- 支配w" role="presentation" style="position: relative;">ww的点可以有多个,但是至少会有一个。显然,对于起点以外的点,它们都有两个平凡的支配点,一个是自己,一个是起点。
- 在支配w" role="presentation" style="position: relative;">ww的点中,如果一个支配点i≠wi≠w" role="presentation" style="position: relative;">i≠wi≠wi≠wi≠w满足i" role="presentation" style="position: relative;">ii被w" role="presentation" style="position: relative;">ww剩下的所有非平凡支配点支配,则这个i" role="presentation" style="position: relative;">ii称作w" role="presentation" style="position: relative;">ww的最近支配点(immediatedominator)" role="presentation" style="position: relative;">(immediatedominator)(immediatedominator),记作idom(w)" role="presentation" style="position: relative;">idom(w)idom(w)。
如果我们把图的起点称作s" role="presentation" style="position: relative;">ss,那么除s" role="presentation" style="position: relative;">ss以外每个点均存在唯一的idom" role="presentation" style="position: relative;">idomidom。于是,连上所有r" role="presentation" style="position: relative;">rr以外的idom(w)→widom(w)→w" role="presentation" style="position: relative;">idom(w)→widom(w)→widom(w)→widom(w)→w的边,就能得到一棵树,其中每个点支配它子树中的所有点,它就是支配树。
下面我们来考虑一个问题:给定一个起点s" role="presentation" style="position: relative;">ss和一个终点t" role="presentation" style="position: relative;">tt,询问删掉哪些点能够使s" role="presentation" style="position: relative;">ss无法到达t" role="presentation" style="position: relative;">tt。
不难发现,支配点与割点并不相同,我们可以用某位大佬的图证明这一观点
显然在这种情况中即使我们割掉割点依然能使s" role="presentation" style="position: relative;">ss走到t" role="presentation" style="position: relative;">tt点。所以我们没有办法使用割点来解决这个问题。
那么我们如何处理这个问题呢???
如果该DAG" role="presentation" style="position: relative;">DAGDAG是一棵树,那没什么好说的,显然有fa[u]==idom[u]" role="presentation" style="position: relative;">fa[u]==idom[u]fa[u]==idom[u],那么路径s−>v" role="presentation" style="position: relative;">s−>vs−>v上的点都应该是支配点,直接O(n)" role="presentation" style="position: relative;">O(n)O(n)解决了
如果不是树该肿么办?我们考虑用拓扑序建立支配树:
由于我们是根据拓扑序来进行处理的那么当我们处理到第i" role="presentation" style="position: relative;">ii个节点u" role="presentation" style="position: relative;">uu时,第1" role="presentation" style="position: relative;">11~i+1" role="presentation" style="position: relative;">i+1i+1个节点显然已经处理完了,对于所有能够直接到达点u" role="presentation" style="position: relative;">uu的节点,我们求出它们在支配树上的lca" role="presentation" style="position: relative;">lcalca v" role="presentation" style="position: relative;">vv,这个点v" role="presentation" style="position: relative;">vv就是点u" role="presentation" style="position: relative;">uu在支配树上的父亲。
如果使用倍增求lca" role="presentation" style="position: relative;">lcalca,那么O((n+m)log2n)" role="presentation" style="position: relative;">O((n+m)log2n)O((n+m)log2n)的时间内实现。