Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P4455 [CQOI2018]社交网络

P4455 [CQOI2018]社交网络

矩阵树定理外向树板子。

查看代码
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
#include <cstdio>
#include <algorithm>
using namespace std;
template <class Type>
void read(Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0';
flag && (x = ~x + 1);
}
template <class Type>
void write(Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar(x % 10 + '0');
}
const int N = 260, mod = 1e4 + 7;
int n, m, A[N][N];
int del ()
{
int res = 1;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
{
while (A[i][i])
{
int t = A[j][i] / A[i][i];
for (int k = i; k <= n; k++)
(A[j][k] -= t * A[i][k] % mod) %= mod;
swap(A[i], A[j]);
res *= -1;
}
swap(A[i], A[j]);
res *= -1;
}
for (int i = 1; i <= n; i++)
res = res * A[i][i] % mod;
return res;
}
int main ()
{
read(n), read(m);
for (int a, b; m; m--)
{
read(a), read(b);
a--, b--;
A[a][a]++, A[b][a]--;
}
n--;
write((del() + mod) % mod);
return 0;
}