-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscs_count.cpp
68 lines (68 loc) · 1.44 KB
/
scs_count.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MOD = 10007;
int INV[MOD];
//求ax = 1( mod m) 的x值,就是逆元(0<a<m)
long long inv(long long a,long long m) {
if(a == 1)return 1;
return inv(m%a,m)*(m-m/a)%m;
}
struct Matrix {
int mat[330][330];
void init() {
memset(mat,0,sizeof(mat));
}
void addEdge(int u,int v) {
mat[u][v]=-1;
mat[u][u]++;
}
int det(int n) { //求行列式的值模上MOD,需要使用逆元
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
mat[i][j] = (mat[i][j]%MOD+MOD)%MOD;
int res = 1;
for(int i = 0; i < n; i++) {
for(int j = i; j < n; j++)
if(mat[j][i]!=0) {
for(int k = i; k < n; k++)
swap(mat[i][k],mat[j][k]);
if(i != j)
res = (-res+MOD)%MOD;
break;
}
if(mat[i][i] == 0) {
res = -1;//不存在(也就是行列式值为0)
break;
}
for(int j = i+1; j < n; j++) {
//int mut = (mat[j][i]*INV[mat[i][i]])%MOD;//打表逆元
int mut = (mat[j][i]*inv(mat[i][i],MOD))%MOD;
for(int k = i; k < n; k++)
mat[j][k] = (mat[j][k]-(mat[i][k]*mut)%MOD+MOD)%MOD;
}
res = (res * mat[i][i])%MOD;
}
return res;
}
};
Matrix ret;
int main() {
int t;
cin>>t;
while(t--) {
int n,m;
scanf("%d%d",&n,&m);
ret.init();
for(int i=0;i<m;i++){
int u,v;
scanf("%d%d",&u,&v);
ret.addEdge(u,v);
ret.addEdge(v,u);
}
printf("%d\n",ret.det(n-1));
}
return 0;
}