QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#662829#5139. DFS Order 2YurilyWA 113ms473756kbC++202.8kb2024-10-21 10:57:252024-10-21 10:57:29

Judging History

你现在查看的是最新测评结果

  • [2024-10-21 10:57:29]
  • 评测
  • 测评结果:WA
  • 用时:113ms
  • 内存:473756kb
  • [2024-10-21 10:57:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAX=505;
const long long MOD=998244353;
int f[MAX][MAX],g[MAX],pred[MAX][MAX][MAX],d[MAX][MAX];
long long A[MAX];
struct edge{
	int nxt,to;
};
int h[MAX],tot,son[MAX];
edge e[MAX*2];
int n,tmp[MAX];
void pre(int u,int fa){
	son[u]=1;
	g[u]=1; 
	int cnt=0;
	for(int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)
			continue;
		pre(v,u);
		cnt++;
		son[u]+=son[v];
		g[u]=g[u]*g[v]%MOD;
	}
	g[u]=g[u]*A[cnt]%MOD;
}
long long quick_pow(long long x,long long y){
	long long res=1;
	while(y){
		if(y&1)
			res=res*x%MOD;
		x=x*x%MOD;
		y>>=1;
	}
	return res;
}
void pre_dp(int u,int fa){
	int cnt=0;
	long long s=1;
	for(int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)
			continue;
		tmp[++cnt]=v;
		s=s*g[v]%MOD;
	}
	for(int i=1;i<=cnt;++i){
		pred[tmp[i]][0][0]=1;
		for(int j=1;j<=cnt;++j){
			if(j==i)
				continue;
			for(int l=j-(j>=i?1:0);l>=1;--l){
				for(int k=1;k<=son[u]-son[tmp[i]]-1;++k){
					if(k-son[tmp[j]]>=0)
						pred[tmp[i]][k][l]=(pred[tmp[i]][k][l]+pred[tmp[i]][k-son[tmp[j]]][l-1])%MOD;
				//	if(tmp[i]==3){
				//		cout<<tmp[j]<<" "<<k<<" "<<l<<"$"<<pred[tmp[i]][k][l]<<endl;
				//	}
				}
			}
		}
		for(int k=0;k<=son[u]-son[tmp[i]]-1;++k){
			for(int l=0;l<=cnt-1;++l){
			//	if(tmp[i]==3)
			//		cout<<tmp[i]<<" "<<k<<" "<<l<<" "<<pred[tmp[i]][k][l]<<endl;
				d[tmp[i]][k]=(d[tmp[i]][k]+(__int128)pred[tmp[i]][k][l]*A[l]*A[cnt-1-l]*s*quick_pow(g[tmp[i]],MOD-2)%MOD)%MOD;
			}
		}		
	}
	
	for(int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)
			continue;
		pre_dp(v,u);
	}	
}
void dp(int u,int k,int fa){
	int cnt=0;
	for(int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)
			continue;
		tmp[++cnt]=v;
	}
	for(int i=1;i<=cnt;++i){
		for(int j=1;j<=son[u]-son[tmp[i]];++j){
			if(k-j>=0)
				f[tmp[i]][k]=(f[tmp[i]][k]+(long long)f[u][k-j]*d[tmp[i]][j-1]%MOD)%MOD;
		}
	//	cout<<"*"<<tmp[i]<<" "<<k<<" "<<f[tmp[i]][k]<<endl;
	}
	
	for(int i=h[u];i;i=e[i].nxt){
		int v=e[i].to;
		if(v==fa)
			continue;
		dp(v,k,u);
	}
}
// ¿ì¶Á 
int read(){
	int x = 0, f = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-'){
			f = -1;
		}
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		x = x*10+c-'0';
		c = getchar();
	}
	return x*f;
}
void addedge(int u,int v){
	e[++tot].to=v;
	e[tot].nxt=h[u];
	h[u]=tot;
} 
int main(){
	cin>>n;
	A[0]=1;
	for(int i=1;i<=n;++i)
		A[i]=A[i-1]*i%MOD;
	
	for(int i=1;i<=n-1;++i){
		int u=read(),v=read();
		addedge(u,v);
		addedge(v,u);
	}
	
	pre(1,0);
	
	d[1][0]=1;
	pre_dp(1,0);
	
	f[0][0]=1;
	f[1][1]=1;
	for(int i=1;i<=n;++i)
		dp(1,i,0);
//	cout<<f[9][3]<<endl;
//	cout<<d[3][2]<<endl;	
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			printf("%d ",(long long)f[i][j]*g[i]%MOD);
		}
		printf("\n");
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9980kb

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: 0
Accepted
time: 2ms
memory: 16076kb

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 4 2 2 8 2 2 4 
0 0 0 4 4 4 4 4 4 0 
0 0 0 0 4 4 4 4 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 4 2 2 8 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:

ok 100 numbers

Test #3:

score: 0
Accepted
time: 3ms
memory: 104312kb

input:

100
18 100
91 87
28 83
11 98
51 52
24 91
72 53
18 19
89 16
77 35
26 25
73 16
96 70
56 44
69 10
63 30
54 95
39 66
58 98
8 71
58 65
74 73
2 64
12 19
32 81
31 54
43 41
84 59
55 75
72 81
59 37
10 94
93 2
64 47
13 32
36 84
28 22
30 28
25 77
47 6
80 52
54 17
23 40
47 88
49 53
65 27
99 59
25 70
91 9
74 1
7...

output:

8388559 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 0 0 0 0 62914557 0 62914557 62914557 0 62914557 0 0 0 62914557 0 62914557...

result:

ok 10000 numbers

Test #4:

score: -100
Wrong Answer
time: 113ms
memory: 473756kb

input:

500
382 156
418 376
91 15
142 274
449 174
375 82
118 175
421 458
361 222
14 474
11 324
368 341
227 424
231 249
81 435
250 271
118 38
147 61
124 408
135 1
244 316
301 80
39 313
90 118
290 465
465 250
277 341
8 105
319 373
305 379
309 200
180 398
47 489
463 259
173 492
494 343
251 193
111 32
401 270
4...

output:

478607072 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer 1st numbers differ - expected: '219078761', found: '478607072'