欲学矩阵树定理必先自宫学习一些行列式的姿势
然后做一道例题
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long ll;
int T, n, m, uu, vv;
double w[15][15];
const double eps=1e-7;
void gauss(){
n--;
for(int i=1; i<=n; i++){
int maxi=i;
for(int j=i+1; j<=n; j++)
if(w[j][i]>w[maxi][i])
maxi = j;
swap(w[maxi], w[i]);
if(fabs(w[maxi][i])<eps){
printf("0\n");
return ;
}
for(int j=i+1; j<=n; j++){
double bil=w[j][i]/w[i][i];
for(int k=i; k<=n; k++)
w[j][k] -= bil * w[i][k];
}
}
double ans=1;
for(int i=1; i<=n; i++)
ans *= w[i][i];
printf("%.0f\n", fabs(ans));
}
int main(){
cin>>T;
while(T--){
scanf("%d %d", &n, &m);
memset(w, 0, sizeof(w));
while(m--){
scanf("%d %d", &uu, &vv);
w[uu][uu]++; w[vv][vv]++;
w[uu][vv]--; w[vv][uu]--;
}
gauss();
}
return 0;
}
原文地址:https://www.cnblogs.com/poorpool/p/8883213.html
时间: 2024-10-09 22:05:15