QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#392260 | #6623. Perfect Matchings | tz3528 | WA | 11ms | 159600kb | C++20 | 1.1kb | 2024-04-17 13:20:44 | 2024-04-17 13:20:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=4010;
const int mod=998244353;
int fir[maxn],to[2*maxn],Next[2*maxn],edge;
long long cnt[maxn],dp[maxn][maxn][2],mul[maxn];
void add(int x,int y){
to[++edge]=y;Next[edge]=fir[x];fir[x]=edge;
}
void dfs(int now,int fa){
dp[now][0][0]=cnt[now]=1;
for(int i=fir[now];i;i=Next[i]){
int z=to[i];
if(z==fa) continue;
dfs(z,now);
for(int j=cnt[now]/2;j>=0;j--){
for(int l=cnt[z]/2;l>=0;l--){
if(l>0){
(dp[now][j+l][0]+=dp[now][j][0]*(dp[z][l][0]+dp[z][l][1])%mod)%=mod;
(dp[now][j+l][1]+=dp[now][j][1]*(dp[z][l][0]+dp[z][l][1])%mod)%=mod;
}
(dp[now][j+l+1][1]+=dp[now][j][0]*dp[z][l][0]%mod)%=mod;
}
}
cnt[now]+=cnt[z];
}
}
int main(){
int n;
cin>>n;
for(int i=1;i<=2*n-1;i++){
int u,v;cin>>u>>v;
add(u,v);add(v,u);
}
mul[0]=1;
dfs(1,0);
for(int i=1;i<=n;i++) mul[i]=mul[i-1]*(2*i-1)%mod;
long long ans=0;
for(int i=0;i<=n;i++){
if(i&1) (ans-=(dp[1][i][0]+dp[1][i][1])*mul[n-i]%mod)%=mod;
else (ans+=(dp[1][i][0]+dp[1][i][1])*mul[n-i]%mod)%=mod;
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
2 1 2 1 3 3 4
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3760kb
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: 3824kb
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: 3748kb
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: 3780kb
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: 1ms
memory: 5804kb
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: 1ms
memory: 5652kb
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: 11ms
memory: 159600kb
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:
-660749750
result:
wrong answer 1st numbers differ - expected: '337494603', found: '-660749750'