QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#100723 | #5139. DFS Order 2 | lgvc# | WA | 0ms | 9888kb | C++23 | 2.8kb | 2023-04-27 19:35:21 | 2023-04-27 19:35:23 |
Judging History
answer
//这回只花了114514min就打完了。
//真好。记得多手造几组。
#include <bits/stdc++.h>
#define int long long
#define pai 3.141592653589793238462643383279502884197169399375105820
#define MOD 998244353
#define eps 0.00000001
inline int min(int a,int b) {return a<b?a:b;}
inline int max(int a,int b) {return a>b?a:b;}
#define ULL unsigned long long
#define LL long long
#define INF 0x3f3f3f3f
#define INF_LL 0x3f3f3f3f3f3f3f3f
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
*pp++=ch;
}
inline void pcc(){
fwrite(buf2,1,pp-buf2,stdout);
pp=buf2;
}
inline int read(void) {
int w=1;
register int x(0);register char c(getchar());
while(c<'0'||c>'9') {if(c=='-') w=-1;c=getchar();}
while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return w*x;
}
void write(int x) {
if(x<0) pc('-'),x=-x;
static int sta[20];
int top=0;
do {
sta[top++]=x%10,x/=10;
} while(x);
while(top) pc(sta[--top]+48);
}
void we(int x) {
write(x);
pc('\n');
}
inline bool cmp_xi(int a,int b) {return a<b;}
inline bool cmp_da(int a,int b) {return a>b;}
int N,hd[509],dd[509][509],to[1009],nxt[1009],siz[509],p[509],px[509],k,dp[509][509][509];
inline void l(int u,int v) {nxt[++k]=hd[u],to[k]=v,hd[u]=k;}
void dfs(int n,int f) {
siz[n]=1;p[n]=1;
int dg=0;
for(int i=hd[n];i;i=nxt[i]) {
if(to[i]==f) continue;
dfs(to[i],n);
dg++;
siz[n]+=siz[to[i]];
p[n]=p[n]*p[to[i]]%MOD;
p[n]=p[n]*dg%MOD;
}
dp[n][n][1]=p[n];
for(int i=hd[n];i;i=nxt[i]) {
if(to[i]==f) continue;
for(int j=0;j<=dg;j++) {
for(int k=0;k<=siz[n];k++) {
dd[j][k]=0;
}
}
dd[0][0]=1;
int aq=1;
for(int j=hd[n];j;j=nxt[j]) {
if(to[j]==f||to[j]==to[i]) continue;
aq=aq*p[to[j]]%MOD;
for(int k=dg;k>=1;k--) {
for(int l=siz[to[j]];l<=siz[n];l++) {
dd[k][l]=(dd[k][l]+dd[k-1][l-siz[to[j]]])%MOD;
}
}
}
for(int k=0;k<=siz[n];k++) {
int as=0;
for(int j=0;j<=dg;j++) {
if(!dd[j][k]) continue;
int va=dd[j][k]*px[j]%MOD;
as=(as+va)%MOD;
}
as=as*aq%MOD;
if(as==0) continue;
for(int l=1;l<=N;l++) {
for(int x=1;x<=siz[to[i]];x++) {
if(dp[to[i]][l][x]) dp[n][l][x+k+1]=(dp[n][l][x+k+1]+dp[to[i]][l][x]*as)%MOD;
}
}
}
}
}
signed main(void) {
//freopen("m.in","r",stdin);
//freopen("m.out","w",stdout);
N=read();
px[0]=1;
for(int i=1;i<=N;i++) px[i]=px[i-1]*i%MOD;
for(int i=1;i<N;i++) {
int u=read(),v=read();
l(u,v),l(v,u);
}
dfs(1,0);
for(int i=1;i<=N;i++) {
for(int j=1;j<=N;j++) {
printf("%lld ",dp[1][i][j]);
}
printf("\n");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9888kb
input:
5 1 2 1 3 3 4 3 5
output:
4 0 0 0 0 0 2 0 0 2 0 2 2 0 0 0 0 1 2 1 0 0 1 2 1
result:
ok 25 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 9664kb
input:
10 9 2 9 6 10 5 1 5 1 6 9 3 5 8 4 3 7 9
output:
24 0 0 0 0 0 0 0 0 0 0 0 0 2 2 2 6 2 2 4 0 0 0 2 4 4 2 4 4 0 0 0 0 0 2 4 4 2 4 4 0 12 0 0 0 0 0 12 0 0 0 12 0 0 12 0 0 0 0 0 0 0 0 2 2 2 6 2 2 4 0 0 6 6 0 0 0 0 6 6 0 0 12 0 0 12 0 0 0 0 0 0 6 6 0 0 0 0 6 6
result:
wrong answer 14th numbers differ - expected: '4', found: '2'