题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=4031 题解: Matrix-tree定理解决生成树计数问题,其中用到高斯消元法求上三角矩阵,其中消元用的是辗转相除法. 代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int mod = 1e9; ; typedef long long L…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4031 矩阵树定理的模板题(第一次的矩阵树定理~): 有点细节,放在注释里了. 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long ll; int const mod=1e9; ][],d[][],sid[][],tot,…
裸的矩阵树定理.求行列式的时候答案要在中间统计,因为交换两个行会使答案取反. #include <bits/stdc++.h> using namespace std; const int N = 10 + 5; const int M = 100 + 5; const int mod = 1000000000; char s[N][N]; int n, m, a[M][M], id[N][N]; void add (int u, int v) { --a[u][v], --a[v][u],…