QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#385605#8570. Idola-TreezhouhuanyiWA 1804ms64280kbC++142.4kb2024-04-10 21:37:402024-04-10 21:37:41

Judging History

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

  • [2024-04-10 21:37:41]
  • 评测
  • 测评结果:WA
  • 用时:1804ms
  • 内存:64280kb
  • [2024-04-10 21:37:40]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#define N 300000
#define M 5000000
#define mod 998244353
using namespace std;
const int inv2=(mod+1)>>1;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
int T,n,sC,ans,tans,fa[N+1],C[3][3],l1,r1,l2,r2;
long long dp[N+1][3],delta[N+1],tong[N+1],dque[N+1],dque2[M+1];
bool used[N+1];
vector<int>E[N+1];
void add(int x,int y)
{
	E[x].push_back(y),E[y].push_back(x);
	return;
}
void adder(int x,int y,int d)
{
	for (int i=0;i<=2;++i)
		for (int j=0;j<=i;++j)
			dp[x][i]+=dp[y][j]*C[i][j]*d;
	return;
}
void dfs(int x)
{
	used[x]=dp[x][0]=1;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			fa[E[x][i]]=x,dfs(E[x][i]),adder(x,E[x][i],1);
	return;
}
void dfs2(int x)
{
	Adder(ans,1ll*(dp[x][2]%mod)*inv2%mod);
	if (E[x].size()==1) delta[x]=2*dp[x][1];
	for (int i=0;i<E[x].size();++i)
		if (fa[E[x][i]]==x)
			adder(x,E[x][i],-1),adder(E[x][i],x,1),dfs2(E[x][i]),adder(E[x][i],x,-1),adder(x,E[x][i],1);
	return;
}
int main()
{
	int x,y,rst;
	for (int i=0;i<=2;++i) C[i][0]=1;
	for (int i=1;i<=2;++i)
		for (int j=1;j<=i;++j)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	T=read();
	while (T--)
	{
		n=read(),sC=read()-(n-1),ans=tans=0;
		for (int i=1;i<=n;++i)
		{
			E[i].clear(),used[i]=fa[i]=0;
			for (int j=0;j<=2;++j) dp[i][j]=0;
		}
		for (int i=1;i<=n-1;++i) x=read(),y=read(),add(x,y);
		if (n==2)
		{
			Adder(ans,1);
			for (int i=0;i<=sC;++i)
			{
				if (i) Adder(ans,1);
				Adder(tans,1ll*ans*ans%mod*ans%mod);
			}
			printf("%d\n",tans);
		}
		else
		{
			dfs(1),dfs2(1),l1=l2=1,r1=r2=0;
			for (int i=1;i<=n;++i)
				if (E[i].size()==1)
					dque[++r1]=delta[i]+n-2;
			sort(dque+1,dque+r1+1);
			for (int i=0;i<=sC;++i)
			{
				if (i)
				{
					if (l1<=r1&&(l2==r2+1||dque[l1]<dque2[l2])) Adder(ans,dque[l1]%mod),dque2[++r2]=dque[l1]+((n-2)<<1),++l1;
					else Adder(ans,dque2[l2]%mod),dque2[++r2]=dque2[l2]+((n-2)<<1),++l2;
					if (r2>2000000)
					{
						for (int i=r2-l2+1;i>=1;--i) dque2[i]=dque2[i+l2-1];
						r2-=(l2-1),l2=1;
					}
				}
				rst=MD(ans+1ll*i*i%mod),Adder(tans,1ll*rst*rst%mod*rst%mod);
			}
			printf("%d\n",tans);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 10844kb

input:

2
4 3
1 4
1 3
2 1
4 4
1 4
1 3
2 1

output:

3375
25327

result:

ok 2 tokens

Test #2:

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

input:

4
4 3
1 4
1 3
2 1
4 4
1 4
1 3
2 1
5 4
1 4
1 3
1 2
5 4
5 5
1 4
1 3
1 2
5 4

output:

3375
25327
54872
249984

result:

ok 4 tokens

Test #3:

score: 0
Accepted
time: 1706ms
memory: 56704kb

input:

4
300000 50000000
216838 200677
44849 12926
125086 157230
26195 29767
241694 21336
21336 24457
105861 84565
184655 45583
175336 97945
286044 30927
295273 249694
109469 1566
193560 251229
176229 288707
206166 13532
166218 264413
299977 95587
159105 48116
57912 82606
97296 193689
115029 121192
68068 1...

output:

968050473
546482457
9595680
694101802

result:

ok 4 tokens

Test #4:

score: 0
Accepted
time: 1745ms
memory: 56432kb

input:

4
300000 49999999
260729 131757
51432 46938
257303 178692
218606 108144
299084 259822
82091 231405
101255 218808
287507 101249
29597 151244
43164 198032
122336 162072
177969 62812
277824 35758
182087 258797
235155 33806
188695 76915
289006 141702
39100 183183
224949 156588
9827 173233
27349 286822
1...

output:

283884918
837489229
12901428
323340145

result:

ok 4 tokens

Test #5:

score: 0
Accepted
time: 1728ms
memory: 59700kb

input:

4
300000 50000000
187086 121551
163664 292500
40569 125891
280767 56246
127162 299705
207527 280767
252551 217178
73197 278560
274282 31937
121290 280767
220367 278560
187814 40569
187372 278560
95157 131908
119390 161684
202404 283778
226289 130192
294021 278560
50286 102006
21592 222623
285215 237...

output:

4850582
364539310
683543335
559022036

result:

ok 4 tokens

Test #6:

score: 0
Accepted
time: 1712ms
memory: 58152kb

input:

4
300000 50000000
225743 104304
178831 182636
22896 17048
96503 294029
294029 28084
38933 104195
294029 1583
224079 175121
8797 197089
81985 139893
184175 103991
39351 217336
127576 82268
294029 292994
145502 294859
63119 104069
294029 41437
236951 199792
157992 294029
249477 284128
136077 294029
65...

output:

536508840
693675397
413103274
759128961

result:

ok 4 tokens

Test #7:

score: 0
Accepted
time: 1793ms
memory: 59748kb

input:

4
300000 50000000
246788 228391
158979 271301
96237 233512
276470 143087
132635 100991
189228 201152
1506 10986
75594 100408
279681 127708
140194 83425
50807 272520
277215 107214
249687 77890
261893 11907
109314 121422
76821 170561
11602 233066
80094 28275
27473 70572
130573 16191
13008 289605
25353...

output:

229607225
752154895
217060859
960988279

result:

ok 4 tokens

Test #8:

score: 0
Accepted
time: 1804ms
memory: 55828kb

input:

4
300000 50000000
282645 78888
157049 242271
143611 216821
287822 256908
2275 263546
49651 72865
31980 207555
107608 204451
138876 149271
175134 283496
8765 266276
288773 161294
250433 198847
292442 23211
93376 281917
221760 81331
133157 239663
276759 27628
115322 150583
89351 283086
291870 12125
68...

output:

62551856
430534707
675000909
391405102

result:

ok 4 tokens

Test #9:

score: 0
Accepted
time: 1792ms
memory: 64280kb

input:

4
300000 50000000
294569 56297
172540 287752
61940 152205
197674 254245
24085 113380
82637 123004
47497 92473
32184 178733
277456 157565
21776 156798
137130 134095
110025 202055
174662 297197
60043 118646
4537 248467
273141 53510
238177 252865
234966 233515
289687 229746
298433 191752
120484 36179
2...

output:

195781417
673490465
850215681
815198198

result:

ok 4 tokens

Test #10:

score: 0
Accepted
time: 1230ms
memory: 52368kb

input:

4
36778 50000000
17602 27103
25759 23876
24338 4623
29585 32937
25324 18644
2950 25005
25234 8990
10680 32086
9568 25870
23421 16592
1809 18727
29491 17171
22903 27836
4496 20939
25152 3804
12390 16492
3484 31766
6824 25795
1411 28354
3077 17532
6033 36029
11689 15579
20720 35844
5484 2622
15596 536...

output:

135800108
231398541
778024906
624480729

result:

ok 4 tokens

Test #11:

score: 0
Accepted
time: 1242ms
memory: 48516kb

input:

4
300000 29286167
155087 68009
83184 149687
206954 8699
86662 141944
237475 242716
124487 225583
168790 57088
207434 196893
573 4579
71930 257825
193317 77567
143825 182638
294310 270719
180399 209962
32628 203666
250650 234364
254067 255639
14682 227300
84292 38937
95079 54215
132911 56983
286874 1...

output:

741171004
852827875
22231673
170720066

result:

ok 4 tokens

Test #12:

score: 0
Accepted
time: 1038ms
memory: 49072kb

input:

4
300000 300000
175617 119821
181516 243657
160218 215766
162419 187680
293075 168627
290423 228281
274959 98317
107502 76378
79894 239145
45063 32200
69024 209908
1914 38016
94743 179968
32123 245964
295205 76517
97609 38830
189696 241669
137230 69860
66658 181410
70572 238631
156044 108622
108815 ...

output:

791655481
435035749
574582056
506992226

result:

ok 4 tokens

Test #13:

score: 0
Accepted
time: 1189ms
memory: 32936kb

input:

4
6 47918926
4 3
6 1
1 5
5 4
5 2
6 49261475
6 4
5 6
5 3
4 2
6 1
6 47347415
3 6
6 4
2 6
6 5
1 5
6 46149726
1 2
5 3
5 4
2 4
2 6

output:

593706496
305830436
556194176
708898110

result:

ok 4 tokens

Test #14:

score: 0
Accepted
time: 1202ms
memory: 32872kb

input:

4
6 49429002
2 1
2 4
2 6
6 5
3 6
7 45760900
5 7
7 2
6 2
7 1
3 2
4 7
6 47061835
6 5
6 3
6 1
2 6
6 4
4 47410821
1 4
1 3
3 2

output:

536172407
533054157
561317786
749859281

result:

ok 4 tokens

Test #15:

score: -100
Wrong Answer
time: 1049ms
memory: 32872kb

input:

4
6 49726215
1 6
2 6
6 3
6 5
2 4
2 50000000
1 2
8 49331348
7 3
7 8
5 6
4 3
6 3
2 4
1 7
5 45313556
2 3
4 3
3 5
5 1

output:

429791300
697873097
307298104
165844147

result:

wrong answer 2nd words differ - expected: '656547393', found: '697873097'