专栏文章

矩阵树定理

个人记录参与者 1已保存评论 0

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
0 条
当前快照
1 份
快照标识符
@miqbrcds
此快照首次捕获于
2025/12/04 02:12
3 个月前
此快照最后确认于
2025/12/04 02:12
3 个月前
查看原文

矩阵树定理

给定带权无向图 GG,求出 TeTwe\sum_T\prod_{e \in T}w_e 的值。

定义

  • 定义 [n]={1,2,3,,n}[n] = \{1, 2, 3, \cdots, n\}
  • 对于无向图,定义 D(G)D(G) 为其度数矩阵,有:D(G)ij={degii=j0ijD(G)_{ij} = \left\{\begin{matrix} \deg_i & i = j \\ 0 & i \ne j \end{matrix}\right..
  • 对于有向图,定义 Din(G)D^{\text{in}}(G)Dout(G)D^{\text{out}}(G) 分别表示其入度矩阵和出度矩阵,有:Din(G)ij={degiini=j0ij,Dout(G)ij={degiouti=j0ijD^{\text{in}}(G)_{ij} = \left\{\begin{matrix} \deg^{\text{in}}_i & i = j \\ 0 & i \ne j \end{matrix}\right., D^{\text{out}}(G)_{ij} = \left\{\begin{matrix} \deg^{\text{out}}_i & i = j \\ 0 & i \ne j \end{matrix}\right..
  • 定义 A(G)A(G) 为图的邻接矩阵。A(G)ijA(G)_{ij} 表示 ii 连向 jj 的边的数量。
  • 定义无向图的 Laplace 矩阵 LLL(G)=D(G)A(G)L(G) = D(G) - A(G)。有向图的情况可以类似的定义 LinL^{\text{in}}LoutL^{\text{out}}.
  • 定义图 GGuu 为根的根向树和叶向树的数量分别为 troot(G,u)t^{\text{root}}(G, u)tleaf(G,u)t^{\text{leaf}}(G, u)
  • 定义矩阵 AA 的子矩阵 AS,TA_{S, T} 为选取 iSi \in SjTj \in T 构成的元素。
  • 定义有向图 GG 的关联矩阵为 M(G)M(G)(无向图可以随便定方向),有 Min(G)ij={w(ej)i is the starting point of edge j0otherwise.,Mout(G)ij={w(ej)i is the end of edge j0otherwise.M^{\text{in}}(G)_{ij} = \left\{\begin{matrix} \sqrt{w(e_j)} & \text{i is the starting point of edge j} \\ 0 & \text{otherwise.} \end{matrix}\right., M^{\text{out}}(G)_{ij} = \left\{\begin{matrix} \sqrt{w(e_j)} & \text{i is the end of edge j} \\ 0 & \text{otherwise.} \end{matrix}\right.,令 M(G)=Min(G)Mout(G)M(G) = M^{\text{in}}(G) - M^{\text{out}}(G)
不难发现
Din=Min(Min)T,Dout=Mout(Mout)T,A(G)=Min(Mout)T.D^{\text{in}} = M^{\text{in}} \cdot (M^{\text{in}})^T, D^{\text{out}} = M^{\text{out}}\cdot (M^{\text{out}})^T, A(G) = M^{\text{in}} \cdot (M^{\text{out}})^T.
进而有
Lin(G)=Min(MinMout)T,Lout(G)=(MoutMin)(Mout)T.L^{\text{in}}(G) = M^{\text{in}} \cdot (M^{\text{in}} - M^{\text{out}})^T, L^{\text{out}}(G) = (M^{\text{out}} - M^{\text{in}}) \cdot (M^{\text{out}})^T.
对于无向图有
L(G)=MMTL(G) = M \cdot M^T

定理

  • 对于无向图 GG 和任意的 kk,有 t(G)=detL(G)[n]{k},[n]{k}t(G) = \det L(G)_{[n] \setminus \{k\}, [n] \setminus \{k\}}
  • 对于有向图 GG 和根 uu,有 troot(G)=detLout(G)[n]{u},[n]{u}t^{\text{root}}(G) = \det L^{\text{out}}(G)_{[n] \setminus \{u\}, [n] \setminus \{u\}}tleaf(G)=detLin(G)[n]{u},[n]{u}t^{\text{leaf}}(G) = \det L^{\text{in}}(G)_{[n] \setminus \{u\}, [n] \setminus \{u\}}

证明

引理 1(Cauthy-Binet):
对于 n×mn \times m 的矩阵 AAm×nm \times n 的矩阵 BB,有
det(AB)=S{1,2,,m}S=ndetA[n],SdetBS,[n]\det(AB) = \sum\limits_{S \subseteq \{1, 2, \cdots, m\} \land |S| = n}\det A_{[n], S} \cdot \det B_{S, [n]}
如果 n>mn > m,则必有 det(AB)=0\det(AB) = 0
证明咕了。
引理 2:
对于图 GG 的子图 (V,E)(V', E'),若 EV|E'| \le |V'|,则子图 TT 是一棵以 VVV \setminus V' 为根的根向生成树当且仅当
det(MV,Eout)det(MV,EoutMV,Ein)0\det(M_{V', E'}^{\text{out}}) \det(M_{V', E'}^{\text{out}} - M_{V', E'}^{\text{in}}) \ne 0
且该式的值在不为 00 时,恰好为 eEwe\prod_{e \in E'} w_e
证明:
w(T)=eTwew(T) = \prod_{e \in T} w_e。先把行列式中每行的 we\sqrt{w_e} 提出来,最后的答案再乘上一个 w(E)w(E') 就行了。
先考虑第一个行列式。如果 MV,EoutM_{V', E'}^{\text{out}} 存在某行全是 00(该点集中存在点没有在边集中出现),那么 det(MV,Eout)\det(M_{V', E'}^{\text{out}}) 就是 00。然后又由于每条边只有一个出点,所以每行恰好有一个 11。所以这个式子保证了就有 V=E|V'| = |E'|,但是没有保证 TT 是一棵根向生成树。
现在考虑第二个行列式:MV,EoutMV,EinM_{V', E'}^{\text{out}} - M_{V', E'}^{\text{in}}。这个矩阵中每行只有一个 11,零个或一个 1-1。若 TT 中存在环,这些边为 e1e2eme_1 \to e_2 \to \cdots \to e_m。则行列式会长成形如这样的东西:
[010010001000010000100100001000010100000110001000]\begin{bmatrix} 0 & 1 & 0 & 0 & -1 & 0 & 0 & 0 & \cdots \\ 1 & 0 & 0 & 0 & 0 & -1 & 0 & 0 & \cdots \\ 0 & 0 & -1 & 0 & 0 & 1 & 0 & 0 & \cdots \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & -1 & \cdots \\ 0 & -1 & 0 & 0 & 0 & 0 & 0 & 1 & \cdots \\ -1 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & \cdots \\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots \\ \end{bmatrix}
记从第 ii 行的 1-1 处进入点 ii+1+1 处离开点 ii。回顾消元求解行列式的过程,最后一定会消出一行 00。不存在环,那么就可以从叶子处开始消(叶子的那一行有且仅有一个 11,其余的都是 00),可以把它的父亲所在行的 1-1 消掉。最后消出来的结果其实就是 det(MV,Eout)\det(M_{V', E'}^{\text{out}})
所以当且仅当 TT 是一棵以 VVV \setminus V' 为根的根向生成树时 det(MV,Eout)det(MV,EoutMV,Ein)=det(MV,Eout)2=w(T)0\det(M_{V', E'}^{\text{out}}) \det(M_{V', E'}^{\text{out}} - M_{V', E'}^{\text{in}}) = \det(M_{V', E'}^{\text{out}})^2 = w(T) \ne 0
\square
根据刚刚的证明,有更通用的结论:
Tτ(G,u)eTwe=detLout(G)[n]{u},[n]{u}\sum\limits_{T \in \tau(G, u)} \prod_{e \in T} w_e = \det L^{\text{out}}(G)_{[n]\setminus \{u\}, [n] \setminus \{u\}}
这里的 τ(G,u)\tau(G, u) 表示图 GGuu 为根的根向生成树集合。
时间复杂度是求行列式的 O(n3)\mathcal{O}(n^3)
例题先咕了。

评论

0 条评论,欢迎与作者交流。

正在加载评论...