标签:include swa names sizeof mem tchar i+1 complete clu
luogu上直接swap会CE
度数矩阵-邻接矩阵任意去掉一行\(i\)和一列\(i\)然后求解行列式,取单位矩矩阵乘积
裸的矩阵树啊
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
const int maxn=1e3+9;
const double eps=1e-7;
inline LL Read(){
LL x(0),f=1; char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')f=-1; c=getchar();
}
while(c>='0'&&c<='9')
x=(x<<3)+(x<<1)+c-'0',c=getchar();
return x*f;
}
LL n,m,T;
double D[maxn][maxn];
inline void Solve(){
--n;
for(LL i=1;i<=n;++i){
LL mx=i;
for(LL j=i+1;j<=n;++j)
if(D[j][i]>D[mx][i])
mx=j;
if(D[mx][i]<eps&&D[mx][i]>-eps){
printf("0\n");
return;
}
if(mx!=i){
for(LL j=1;j<=n;++j){
LL c(D[i][j]);
D[i][j]=D[mx][j],D[mx][j]=c;
}
}
for(LL j=i+1;j<=n;++j){
double tmp=D[j][i]/D[i][i];
for(LL k=i;k<=n;++k)
D[j][k]-=tmp*D[i][k];
}
}
double ans=1.0;
for(LL i=1;i<=n;++i)
ans*=D[i][i];
printf("%0.f\n",ans);
}
int main(){
T=Read();
while(T--){
n=Read(),m=Read();
memset(D,0,sizeof(D));
while(m--){
LL u(Read()),v(Read());
++D[u][u],++D[v][v],
--D[u][v],--D[v][u];
}
Solve();
}
return 0;
}
标签:include swa names sizeof mem tchar i+1 complete clu
原文地址:https://www.cnblogs.com/y2823774827y/p/10264412.html