Blog of RuSun

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

P7736 [NOI2021] 路径交点

P7736 [NOI2021] 路径交点

手玩画图,可以发现两条路径中间的交点和的数量即起点和终点直接连接的交点,那么所有的交点和即起点和终点排列的逆序对数。

加深对于 LGV引理 的理解。

一般的 LGV引理 的题目,一般满足只有一组起点和终点的匹配满足要求,逆序对数量为 $0$ 。

在本题中,要求所有起点和终点所有的排列中奇偶差,可以而刚好有逆序对数和定义中吻合,那么直接上结论即可。

或者不考虑 LGV引理 ,直接关心行列式的定义,也可以得到结论。

查看代码
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <cstdio>
#include <vector>
#include <queue>
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';
if (flag) x = ~x + 1;
}
template <class Type, class ...rest>
void read(Type &x, rest &...y) { read(x), read(y...); }
template <class Type>
void write(Type x)
{
if (x < 0) putchar('-'), x = ~x + 1;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
typedef long long LL;
const int N = 2e4 + 10, M = 110, mod = 998244353;
vector <int> g[N];
int K, n[N], m[N], d[N], td[N], f[N], A[M][M];
int det (int n)
{
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] -= (LL)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 = (LL)res * A[i][i] % mod;
return res;
}
int main ()
{
int T; read(T);
while (T--)
{
read(K);
for (int i = 1; i <= K; ++i)
read(n[i]), n[i] += n[i - 1];
for (int i = 1; i < K; ++i) read(m[i]);
for (int i = 1; i <= n[K]; ++i)
td[i] = 0, g[i].clear();
for (int i = 1; i < K; ++i)
for (int a, b; m[i]; --m[i])
{
read(a, b); a += n[i - 1], b += n[i];
++td[b], g[a].push_back(b);
}
for (int st = 1; st <= n[1]; ++st)
{
queue <int> q;
for (int i = 1; i <= n[K]; ++i)
d[i] = td[i], f[i] = 0;
f[st] = 1;
for (int i = 1; i <= n[K]; ++i)
if (!d[i]) q.push(i);
while (!q.empty())
{
int t = q.front(); q.pop();
for (int i : g[t])
{
(f[i] += f[t]) %= mod;
if (!--d[i]) q.push(i);
}
}
for (int i = n[K - 1] + 1; i <= n[K]; ++i)
A[st][i - n[K - 1]] = f[i];
}
write((det(n[1]) + mod) % mod), puts("");
}
return 0;
}