QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#953931#10215. Gona GuniWuyanruAC ✓3039ms531740kbC++143.8kb2025-03-28 08:56:412025-03-28 08:56:41

Judging History

This is the latest submission verdict.

  • [2025-03-28 08:56:41]
  • Judged
  • Verdict: AC
  • Time: 3039ms
  • Memory: 531740kb
  • [2025-03-28 08:56:41]
  • Submitted

answer

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
template<typename A,const int N>
using aya=array<A,N>;
inline int read()
{
	int s=0,w=1;char ch;
	while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
inline ll lread()
{
	ll s=0,w=1;char ch;
	while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
template<const int N,const int M>
struct graph
{
	int head[N+5];
	int ww[M+5];
	int t[M+5];
	int x[M+5];
	int cntm;
	graph(){ cntm=1;}
	inline void clear(int n=N)
	{
		cntm=1;
		for(int i=1;i<=n;i++) head[i]=0;
	}
	inline void ad(int u,int v,int w=0)
	{
		cntm++;
		t[cntm]=v;
		x[cntm]=head[u];
		ww[cntm]=w;
		head[u]=cntm;
	}
	inline void add(int u,int v,int w=0)
	{
		ad(u,v,w);
		ad(v,u,w);
	}
	inline int st(int num){ return head[num];}
	inline int to(int num){ return t[num];}
	inline int nx(int num){ return x[num];}
	inline int w(int num){ return ww[num];}
};
graph<300000,600000>g;
const int mod=998244353;
int dp[300005][2][205];
// 0 : 没有儿子
// 1 : 一个儿子,不在  2 : 一个儿子,在
// 3 : 一车儿子,不在  4 : 一车儿子,在
ll fp[5][205],tp[5][205];
int siz[300005];
ll C[205][205];
ll st[205][205];
int n,m;ll ans;
inline void clear()
{
	g.clear(n);
}
inline void merge(ll *A,int *B,ll *res,int a,int b)
{
	for(int i=0;i<=a;i++) for(int j=0;j<=min(b,m-i);j++) (res[i+j]+=A[i]*B[j])%=mod;
}
inline void Add(ll &a,ll b){ a+=b;if(a>=mod) a-=mod;}
inline void Add(int &a,ll b){ a+=b;if(a>=mod) a-=mod;}
void dfs(int num,int fa)
{
	for(int i=g.st(num);i;i=g.nx(i))
	{
		int p=g.to(i);
		if(p==fa) continue;
		dfs(p,num);
	}

	memset(dp[num],0,sizeof(dp[num]));
	fp[0][0]=1;siz[num]=min(1,m);
	for(int i=g.st(num);i;i=g.nx(i))
	{
		int p=g.to(i);if(p==fa) continue;
		merge(fp[0],dp[p][0],tp[2],siz[num],siz[p]);
		merge(fp[0],dp[p][1],tp[1],siz[num],siz[p]);
		merge(fp[1],dp[p][0],tp[4],siz[num],siz[p]);
		merge(fp[1],dp[p][1],tp[3],siz[num],siz[p]);
		merge(fp[2],dp[p][0],tp[4],siz[num],siz[p]);
		merge(fp[2],dp[p][1],tp[4],siz[num],siz[p]);
		merge(fp[3],dp[p][0],tp[4],siz[num],siz[p]);
		merge(fp[3],dp[p][1],tp[3],siz[num],siz[p]);
		merge(fp[4],dp[p][0],tp[4],siz[num],siz[p]);
		merge(fp[4],dp[p][1],tp[4],siz[num],siz[p]);

		siz[num]=min(siz[num]+siz[p],m);
		for(int p=0;p<5;p++) for(int j=0;j<=siz[num];j++)
		{
			Add(fp[p][j],tp[p][j]);
			tp[p][j]=0;
		}
	}
	for(int i=siz[num];i;i--)
	{
		Add(fp[2][i],fp[2][i-1]);
		Add(fp[4][i],fp[4][i-1]);
	}
	for(int i=0;i<5;i++) for(int j=0;j<=siz[num];j++) Add(ans,fp[i][j]*st[m][j]%mod*(i>=3?2:1)%mod);
	for(int i=1;i<5;i++) for(int j=0;j<=siz[num];j++) (fp[i][j]*=2)%=mod;
	
	for(int i=0;i<5;i++)
	{
		int op=0;
		if(i==2||i==4) op=1;
		for(int j=0;j<=siz[num];j++)
		{
			Add(dp[num][op][j],fp[i][j]);
			fp[i][j]=0;
		}
	}

	// printf("dfs num=%d ans=%lld\n",num,ans);
	// for(int i=0;i<=siz[num];i++) printf("%lld%c",dp[num][0][i]," \n"[i==siz[num]]);
	// for(int i=0;i<=siz[num];i++) printf("%lld%c",dp[num][1][i]," \n"[i==siz[num]]);
}
inline void solve()
{
	n=read(),m=read(),C[0][0]=st[0][0]=1;ans=0;
	for(int i=1;i<=m;i++)
	{
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		for(int j=1;j<=i;j++) st[i][j]=(st[i-1][j-1]+st[i-1][j])*j%mod;
	}

	for(int i=1;i<n;i++) g.add(read(),read());
	dfs(1,1);
	printf("%lld\n",ans);
}
int main()
{
	int T=read();
	while(T--) solve(),g.clear(n);
	return 0;
}
/*
1
5 2
1 2
2 3
1 4
4 5
*/

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 1
1 2
1 3
20 200
1 2
1 3
2 4
1 5
5 6
1 7
6 8
6 9
3 10
4 11
6 12
11 13
4 14
13 15
15 16
6 17
13 18
15 19
13 20

output:

4
286430678

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1448ms
memory: 498036kb

input:

1
300000 200
1 2
1 3
2 4
1 5
4 6
5 7
6 8
4 9
4 10
1 11
11 12
12 13
11 14
11 15
15 16
15 17
11 18
13 19
17 20
11 21
21 22
22 23
21 24
23 25
21 26
26 27
23 28
21 29
23 30
21 31
31 32
32 33
31 34
31 35
31 36
34 37
35 38
31 39
36 40
31 41
41 42
41 43
41 44
43 45
43 46
44 47
45 48
44 49
49 50
41 51
51 52...

output:

247999825

result:

ok single line: '247999825'

Test #3:

score: 0
Accepted
time: 310ms
memory: 10552kb

input:

3000
100 31
1 2
1 3
1 4
1 5
3 6
1 7
4 8
4 9
8 10
2 11
7 12
7 13
7 14
7 15
10 16
15 17
9 18
2 19
4 20
11 21
11 22
12 23
13 24
20 25
3 26
18 27
19 28
1 29
10 30
7 31
28 32
24 33
14 34
11 35
22 36
24 37
20 38
11 39
15 40
25 41
17 42
35 43
39 44
38 45
17 46
23 47
18 48
37 49
29 50
4 51
30 52
7 53
4 54
1...

output:

206703729
241517344
965256040
953191893
971103184
611763581
951769747
605254273
515657073
26158774
230121672
742384467
504292176
95015638
209242429
591984607
47728881
658540538
686302223
589359656
153765564
462000121
877695624
168867090
447225696
468677488
440776261
374615358
105981576
120340771
617...

result:

ok 3000 lines

Test #4:

score: 0
Accepted
time: 991ms
memory: 494200kb

input:

1
300000 200
1 2
2 3
1 4
2 5
5 6
4 7
5 8
8 9
3 10
2 11
10 12
12 13
4 14
6 15
6 16
7 17
13 18
3 19
13 20
18 21
5 22
22 23
20 24
24 25
24 26
9 27
25 28
5 29
5 30
20 31
21 32
24 33
7 34
22 35
32 36
30 37
26 38
30 39
39 40
24 41
37 42
28 43
37 44
16 45
27 46
7 47
16 48
38 49
7 50
29 51
47 52
4 53
31 54
...

output:

634171363

result:

ok single line: '634171363'

Test #5:

score: 0
Accepted
time: 3039ms
memory: 531740kb

input:

1
300000 200
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 5...

output:

378891816

result:

ok single line: '378891816'

Test #6:

score: 0
Accepted
time: 877ms
memory: 494256kb

input:

1
300000 200
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
5 11
6 12
6 13
7 14
7 15
8 16
8 17
9 18
9 19
10 20
10 21
11 22
11 23
12 24
12 25
13 26
13 27
14 28
14 29
15 30
15 31
16 32
16 33
17 34
17 35
18 36
18 37
19 38
19 39
20 40
20 41
21 42
21 43
22 44
22 45
23 46
23 47
24 48
24 49
25 50
25 51
26 52
26 53
2...

output:

435358080

result:

ok single line: '435358080'

Test #7:

score: 0
Accepted
time: 1837ms
memory: 494208kb

input:

1
300000 200
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
...

output:

220992079

result:

ok single line: '220992079'

Test #8:

score: 0
Accepted
time: 2822ms
memory: 528052kb

input:

1
300000 200
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 5...

output:

872442796

result:

ok single line: '872442796'

Test #9:

score: 0
Accepted
time: 2670ms
memory: 513040kb

input:

1
300000 200
1 2
1 3
3 4
3 5
5 6
5 7
7 8
7 9
9 10
9 11
11 12
11 13
13 14
13 15
15 16
15 17
17 18
17 19
19 20
19 21
21 22
21 23
23 24
23 25
25 26
25 27
27 28
27 29
29 30
29 31
31 32
31 33
33 34
33 35
35 36
35 37
37 38
37 39
39 40
39 41
41 42
41 43
43 44
43 45
45 46
45 47
47 48
47 49
49 50
49 51
51 52...

output:

77589834

result:

ok single line: '77589834'

Test #10:

score: 0
Accepted
time: 1884ms
memory: 501780kb

input:

1
300000 200
1 2
1 3
2 4
1 5
1 6
6 7
6 8
8 9
9 10
6 11
11 12
11 13
13 14
11 15
11 16
16 17
17 18
17 19
18 20
16 21
21 22
22 23
22 24
24 25
21 26
26 27
26 28
26 29
27 30
26 31
31 32
31 33
33 34
31 35
31 36
36 37
37 38
36 39
39 40
36 41
41 42
42 43
42 44
44 45
41 46
46 47
46 48
46 49
48 50
46 51
51 52...

output:

137591617

result:

ok single line: '137591617'

Test #11:

score: 0
Accepted
time: 891ms
memory: 494376kb

input:

1
300000 200
1 2
1 3
2 4
1 5
4 6
5 7
6 8
4 9
4 10
3 11
8 12
1 13
7 14
8 15
14 16
7 17
7 18
16 19
3 20
12 21
13 22
9 23
13 24
18 25
10 26
11 27
12 28
13 29
15 30
22 31
23 32
8 33
4 34
16 35
13 36
24 37
6 38
27 39
7 40
39 41
37 42
10 43
37 44
40 45
9 46
16 47
7 48
24 49
34 50
45 51
46 52
43 53
53 54
5...

output:

529039223

result:

ok single line: '529039223'

Extra Test:

score: 0
Extra Test Passed