QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245766 | #6623. Perfect Matchings | 0x4F5DA2 | WA | 58ms | 59244kb | C++14 | 2.6kb | 2023-11-10 11:42:32 | 2023-11-10 11:42:32 |
Judging History
answer
#include <cstdio>
#define int long long
const int maxn = 2000;
const int mp = 998244353;
int n;
struct node{
int nxt;
int to;
}edge[maxn * 4 + 10];
int head[maxn * 2 + 10];
int top;
void AddEdge(int u, int v){
++top;
edge[top].nxt = head[u];
edge[top].to = v;
head[u] = top;
return ;
}
long long ans = 0;
long long f[maxn * 2 + 10][maxn + 10][2];
//int temp[maxn + 10];
int siz[maxn * 2 + 10];
void dfs(int x, int fa){
siz[x] = 1;
f[x][0][0] = 1;
f[x][0][1] = 0;
for(int i = head[x]; i; i = edge[i].nxt){
int y = edge[i].to;
if(y != fa){
dfs(y, x);
siz[x] = siz[x] + siz[y];
for(int j = siz[x]; j > 0; --j){
//k = 0
f[x][j][0] = f[x][j][0] * (f[y][0][0] + f[y][0][1]) % mp;
f[x][j][1] = f[x][j][1] * (f[y][0][0] + f[y][0][1]) % mp;
if(1 <= j){
f[x][j][1] = (f[x][j][1] + f[x][j - 1][0] * f[y][0][0] % mp) % mp;
}
//
for(int k = 1; k <= siz[y] / 2; ++k){
if(k <= j){
f[x][j][0] = (f[x][j][0] + f[x][j - k][0] * (f[y][k][0] + f[y][k][1]) % mp) % mp;
f[x][j][1] = (f[x][j][1] + f[x][j - k][1] * (f[y][k][0] + f[y][k][1]) % mp) % mp;
}
if(k + 1 <= j){
f[x][j][1] = (f[x][j][1] + f[x][j - k - 1][0] * f[y][k][0] % mp) % mp;
}
}
}
}
}
return ;
}
long long ny[maxn * 2 + 10];
long long jc[maxn * 2 + 10];
long long jcny[maxn * 2 + 10];
long long pow_2[maxn * 2 + 10];
long long pow_2ny[maxn * 2 + 10];
long long fun(int cnt){
return (jc[cnt] * pow_2ny[cnt / 2] % mp) * jcny[cnt/2] % mp;
}
signed main(){
scanf("%lld", &n);
pow_2[0] = 1;
pow_2[1] = 2;
pow_2ny[0] = 1;
pow_2ny[1] = 499122177;
jc[0] = 1;
jc[1] = 1;
jcny[0] = 1;
jcny[1] = 1;
ny[0] = 0;
ny[1] = 1;
for(int i = 2; i <= 2 * n; ++i){
//inv[i] = (long long)(p - p / i) * inv[p % i] % p;
ny[i] = (mp - mp / i) * ny[mp % i] % mp;
pow_2[i] = pow_2[i - 1] * 2 % mp;
pow_2ny[i] = pow_2ny[i - 1] * ny[2] % mp;
jc[i] = jc[i - 1] * i % mp;
jcny[i] = jcny[i - 1] * ny[i] % mp;
}
//
/*for(int i = 1; i <= 2 * n; ++i){
if(pow_2[i] >
}*/
//pow_2ny[2] = ny[2];
int u, v;
for(int i = 1; i < 2 * n; ++i){
scanf("%lld%lld", &u, &v);
AddEdge(u, v);
AddEdge(v, u);
}
dfs(1, 0);
/*for(int i = 0; i <= siz[1] / 2; ++i){
printf("%lld %lld\n", f[1][i][0], f[1][i][1]);
}*/
for(int i = 0; i <= n; ++i){
if(i & 1)
ans = (ans - (f[1][i][1] + f[1][i][0]) * fun(2 * n - 2 * i) % mp + mp) % mp;
else
ans = (ans + (f[1][i][1] + f[1][i][0]) * fun(2 * n - 2 * i) % mp) % mp;
}
printf("%lld", ans);
return 0;
}
/*
7
1 2
1 3
2 4
2 5
3 6
3 7
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 1596kb
input:
2 1 2 1 3 3 4
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1668kb
input:
3 1 2 2 3 3 4 4 5 5 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 1596kb
input:
10 2 1 3 2 4 2 5 3 6 3 7 5 8 4 9 3 10 5 11 3 12 9 13 11 14 8 15 5 16 1 17 4 18 1 19 11 20 19
output:
223263378
result:
ok 1 number(s): "223263378"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
10 2 1 3 1 4 1 5 1 6 5 7 3 8 7 9 3 10 2 11 3 12 5 13 12 14 10 15 11 16 10 17 4 18 14 19 4 20 4
output:
225215244
result:
ok 1 number(s): "225215244"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
10 2 1 3 1 4 3 5 3 6 5 7 3 8 5 9 3 10 8 11 2 12 1 13 11 14 2 15 3 16 3 17 2 18 11 19 10 20 3
output:
210104685
result:
ok 1 number(s): "210104685"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
10 2 1 3 2 4 3 5 1 6 2 7 5 8 2 9 3 10 2 11 10 12 7 13 12 14 2 15 2 16 15 17 2 18 6 19 15 20 8
output:
211263144
result:
ok 1 number(s): "211263144"
Test #7:
score: 0
Accepted
time: 0ms
memory: 1744kb
input:
10 2 1 3 2 4 3 5 2 6 2 7 1 8 7 9 3 10 8 11 5 12 6 13 11 14 8 15 1 16 13 17 2 18 14 19 11 20 12
output:
226024809
result:
ok 1 number(s): "226024809"
Test #8:
score: -100
Wrong Answer
time: 58ms
memory: 59244kb
input:
1977 2 1 3 1 4 1 5 4 6 4 7 1 8 3 9 5 10 2 11 3 12 2 13 3 14 2 15 9 16 9 17 2 18 17 19 5 20 16 21 2 22 2 23 15 24 16 25 22 26 14 27 6 28 4 29 24 30 25 31 28 32 15 33 27 34 32 35 24 36 10 37 18 38 15 39 33 40 3 41 27 42 3 43 35 44 15 45 11 46 19 47 21 48 4 49 28 50 6 51 3 52 14 53 14 54 14 55 25 56 18...
output:
796004712
result:
wrong answer 1st numbers differ - expected: '337494603', found: '796004712'