[BZOJ5297][CQOI2018]社交网络
sol
就是求以\(1\)为根的生成树的数量。
直接矩阵树定理。
code
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi()
{
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
const int mod = 10007;
const int N = 255;
int n,m,a[N][N],ans=1;
int main()
{
n=gi();m=gi();
while (m--)
{
int v=gi(),u=gi();
a[u][v]--;a[v][v]++;
}
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
a[i][j]=(a[i][j]%mod+mod)%mod;
for (int i=2;i<=n;++i)
{
for (int j=i+1;j<=n;++j)
while (a[j][i])
{
int t=a[i][i]/a[j][i];
for (int k=i;k<=n;++k) a[i][k]=(a[i][k]-1ll*t*a[j][k]%mod+mod)%mod,swap(a[i][k],a[j][k]);
ans=(mod-ans)%mod;
}
ans=1ll*ans*a[i][i]%mod;
}
printf("%d\n",ans);return 0;
}