计算任意一个图的生成树的个数,是Kirchhoff提出的理论,通常称为Matrix Tree Theorem,原理很简单:
Let G be a graph with V(G)={v1,v2,...,vn},let A={aij}be the adjacentcy matrix of G,and let C={cij}be the n*n matrix, where cij=deg vi if i=j; cij=-aij if i!=j; Then the number of spanning trees of G is the vlaue of any cofactor(余子式) of C
但是需要计算行列式的值,这里需要点小技巧,所以这里选择了LUP分解法来计算。
package trees;
import matrix.DeterminantCalculator;
/**
* 计算任意一个图的生成树的个数,是Kirchhoff提出的理论,通常称为Matrix Tree Theorem
* Let G be a graph with V(G)={v1,v2,...,vn},let A={aij}be the adjacentcy matrix of G,
* and let C={cij}be the n*n matrix, where cij=deg vi if i=j; cij=-aij if i!=j; Then the
* number of spanning trees of G is the vlaue of any cofactor(余子式) of C
* @author xhw
*
*/
public class NumberOfSpanningTree {
/**
* @param args
*/
public static void mai