QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#367203#5139. DFS Order 2Baiyu0123WA 187ms28508kbC++142.2kb2024-03-25 20:12:542024-03-25 20:12:54

Judging History

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

  • [2024-03-25 20:12:54]
  • 评测
  • 测评结果:WA
  • 用时:187ms
  • 内存:28508kb
  • [2024-03-25 20:12:54]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=505,mod=998244353;
vector<int> ed[maxn];
int d[maxn],siz[maxn],n;
int sum[maxn*2],g[maxn][maxn][maxn];
int f[maxn][maxn];
int fac[maxn],inv[maxn];
void lj(int x,int y) {
	ed[x].push_back(y);
	ed[y].push_back(x);
}
void init_dfs(int fa,int u) {
	d[u]=ed[u].size();siz[u]=1;
	for (int i=0;i<ed[u].size();i++) {
		if (ed[u][i]==fa) {
			for (int j=i+1;j<ed[u].size();j++) {
				ed[u][j-1]=ed[u][j];
			}
			d[u]--;
			break;
		}
	}
	for (int i=1;i<=d[u];i++) {
		int v=ed[u][i-1];
		init_dfs(u,v);
		siz[u]+=siz[v];
	}
}
void add(int &x,int y) {
	x=(x+y)%mod;
}
void output(int f[][maxn]) {
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=n;j++) {
			cout<<f[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
}
void getans(int u,int l,int r,int w) {
	for (int i=l;i<=r;i++) {
		int v=ed[u][i-1];
		for (int p=sum[w];p>=0;p--) {
			for (int j=d[u]-1;j>=0;j--) {
				add(g[w][p+siz[v]][j+1],g[w][p][j]);
			}
		}
		sum[w]+=siz[v];
	}
}
int tot=0;
void calc(int u,int l,int r,int w) {
	if (l==r) {
		int v=ed[u][l-1];
		for (int k=1;k<=n-siz[u]+1;k++) {
			for (int p=1;p<=siz[u]-1;p++) {
				for (int j=0;j<=d[u]-1;j++) {
					add(f[v][k+p],
						1ll*f[u][k]*g[w][p-1][j]%mod*fac[j]%mod*fac[d[u]-j-1]%mod*inv[d[u]]%mod);
				}
			}
		}
		return ;
	}
	int mid=(l+r)>>1,rw=++tot;
	memcpy(g[rw],g[w],sizeof(g[w]));sum[rw]=sum[w];
	getans(u,mid+1,r,w);
	getans(u,l,mid,rw);
	calc(u,l,mid,w);
	calc(u,mid+1,r,rw);
}
void dfs(int fa,int u) {
	if (d[u]==0) return;
	g[1][0][0]=1;tot=1;
	calc(u,1,d[u],1);
	for (int i=1;i<=tot;i++) memset(g[i],0,sizeof(g[i]));
	for (int i=1;i<=d[u];i++) {
		int v=ed[u][i-1];
		dfs(u,v);
	}
}
int qpow(int x,int y) {
	ll ret=1,bas=x;
	while (y) {
		if (y&1) ret=ret*bas%mod;
		bas=bas*bas%mod;
		y>>=1;
	}
	return ret;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	for (int i=0;i<=n;i++) inv[i]=qpow(fac[i],mod-2);
	for (int l=2;l<=n;l++) {
		int x,y;cin>>x>>y;
		lj(x,y);
	}
	init_dfs(1,1);
	f[1][1]=1;
	for (int i=1;i<=n;i++) f[1][1]=1ll*f[1][1]*fac[d[i]]%mod;
	dfs(1,1);
	output(f);
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7720kb

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: 0ms
memory: 7812kb

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: 8ms
memory: 8096kb

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: 187ms
memory: 28508kb

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:

219078761 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 587th numbers differ - expected: '551612900', found: '633809726'