QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#379524#8570. Idola-Treeucup_team_qiuly#AC ✓1936ms54356kbC++171.3kb2024-04-06 17:45:382024-04-06 17:45:43

Judging History

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

  • [2024-04-06 17:45:43]
  • 评测
  • 测评结果:AC
  • 用时:1936ms
  • 内存:54356kb
  • [2024-04-06 17:45:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mid ((l+r)/2)
const int N=3e5+5,MOD=998244353;
int T,n,m,rt,d,nw,ans,sz[N];ll t,a[N],s[N],s1[N];queue<ll> q;vector<int> e[N];
void dfs(int u,int f)
{sz[u]=1;s[u]=0;for(auto v:e[u]) if(v!=f) dfs(v,u),sz[u]+=sz[v],s[u]+=s[v]+sz[v];}
void dfs1(int u,int f)
{for(auto v:e[u]) if(v!=f) s1[v]=s1[u]+s[u]-s[v]-sz[v]+n-sz[v],dfs1(v,u);}
ll get()
{
	ll t=q.front();q.pop();
	while(nw<=a[0] && a[nw]<t+d) q.push(a[nw++]);q.push(t+d);return t;
}
void slv()
{
	scanf("%d %d",&n,&m);d=n*2-4;t=ans=a[0]=0;for(int i=1;i<=n;++i) e[i].clear();
	for(int i=1,u,v;i<n;++i) scanf("%d %d",&u,&v),e[u].pb(v),e[v].pb(u);
	if(n==2)
	{
		for(int i=1;i<=m;++i) ans=(ans+1ll*i*i%MOD*i%MOD*i%MOD*i%MOD*i)%MOD;
		printf("%d\n",ans);return;
	}for(int i=1;i<=n;++i) if(e[i].size()>1) rt=i;s1[rt]=0;dfs(rt,0);dfs1(rt,0);
	for(int i=1;i<=n;++i) if(i!=rt) t=(t+s[i]*(n-sz[i])+s1[i]*sz[i])%MOD;
	for(int i=1;i<=n;++i) if(e[i].size()<2) a[++a[0]]=s1[i];
	sort(a+1,a+a[0]+1);for(int i=1;i<=a[0];++i) a[i]=a[i]*2+n-2;
	nw=2;while(!q.empty()) q.pop();q.push(a[1]);
	for(int i=0,t1;i<=m-n+1;++i)
		t1=(t+1ll*i*i)%MOD,ans=(ans+1ll*t1*t1%MOD*t1)%MOD,t=(t+get())%MOD;
	printf("%d\n",ans);
}
int main()
{
	scanf("%d",&T);
	while(T--) slv();return 0;
}

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

詳細信息

Test #1:

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

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: 15528kb

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: 1771ms
memory: 38408kb

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: 1851ms
memory: 37836kb

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: 1855ms
memory: 39452kb

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: 1818ms
memory: 39408kb

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: 1908ms
memory: 39048kb

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: 1936ms
memory: 35740kb

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: 1892ms
memory: 54356kb

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: 1365ms
memory: 33028kb

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: 1310ms
memory: 30024kb

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: 1085ms
memory: 28812kb

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: 1223ms
memory: 15032kb

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: 1270ms
memory: 15484kb

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: 0
Accepted
time: 1205ms
memory: 15564kb

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
656547393
307298104
165844147

result:

ok 4 tokens

Test #16:

score: 0
Accepted
time: 905ms
memory: 15336kb

input:

4
2 1
2 1
6 49045599
4 2
6 1
6 2
2 3
6 5
7 47403164
5 4
4 7
6 4
6 1
3 1
2 1
5 45061409
2 4
2 1
5 4
3 4

output:

1
403846093
637856203
454170631

result:

ok 4 tokens

Test #17:

score: 0
Accepted
time: 1263ms
memory: 15524kb

input:

4
4 48454794
2 4
4 1
3 2
5 48326937
5 1
5 4
3 2
3 1
5 48676454
3 4
4 1
5 1
1 2
6 48862565
6 2
4 2
5 2
2 1
2 3

output:

346937787
946110101
893634681
642310081

result:

ok 4 tokens

Test #18:

score: 0
Accepted
time: 1218ms
memory: 15728kb

input:

4
5 46095989
3 1
4 1
1 2
1 5
5 46073375
4 2
5 4
3 4
1 4
5 48531505
1 5
4 5
2 5
5 3
6 47558014
2 3
6 4
3 5
4 1
5 6

output:

128951803
883389586
226899121
189625473

result:

ok 4 tokens

Test #19:

score: 0
Accepted
time: 1229ms
memory: 15732kb

input:

4
4 45855350
1 4
2 1
4 3
3 49740257
1 2
3 2
4 46480829
1 2
3 1
4 2
4 49937459
1 2
4 2
4 3

output:

605823624
478005949
142328825
551484866

result:

ok 4 tokens

Test #20:

score: 0
Accepted
time: 1244ms
memory: 18796kb

input:

4
4 48451769
4 3
1 3
2 4
6 48177189
6 2
4 3
1 2
3 5
6 3
5 48577030
4 5
2 4
1 5
3 1
5 49630910
3 4
1 5
4 2
4 1

output:

280695405
350730179
81027477
157985696

result:

ok 4 tokens

Test #21:

score: 0
Accepted
time: 1212ms
memory: 14984kb

input:

4
8 49687604
2 8
7 4
3 1
5 6
8 3
7 6
5 1
3 45328134
1 2
1 3
6 47773101
1 4
3 2
6 4
2 4
5 4
6 46139567
2 6
2 3
6 4
2 5
1 2

output:

851791018
997976249
56174545
995045254

result:

ok 4 tokens

Test #22:

score: 0
Accepted
time: 1254ms
memory: 15168kb

input:

4
5 49796273
2 5
1 3
5 1
3 4
5 46614868
3 4
5 4
2 4
1 4
4 49876006
3 4
2 1
3 2
5 49208056
2 1
4 2
2 5
1 3

output:

844326175
597753235
196308105
418510131

result:

ok 4 tokens

Test #23:

score: 0
Accepted
time: 1232ms
memory: 18712kb

input:

4
4 45326185
3 1
2 3
3 4
3 50000000
2 3
1 3
8 48919728
6 1
4 8
4 3
7 8
2 1
8 1
1 5
4 45882405
4 1
1 3
2 4

output:

830463674
893434183
29400274
505479262

result:

ok 4 tokens

Test #24:

score: 0
Accepted
time: 1249ms
memory: 15460kb

input:

4
4 45981477
4 1
1 3
1 2
4 50000000
2 3
3 4
1 4
6 49644522
5 4
1 2
6 3
1 6
3 5
4 46917732
2 4
3 2
2 1

output:

441930004
891846827
12660622
308147414

result:

ok 4 tokens

Test #25:

score: 0
Accepted
time: 1224ms
memory: 18088kb

input:

4
5 46558871
2 4
3 1
3 5
5 4
7 48040830
6 7
1 2
5 2
7 3
7 4
7 1
5 48622955
4 3
1 4
4 5
1 2
8 48009463
3 5
3 4
1 8
7 4
1 4
6 3
4 2

output:

819848891
31449847
684770567
371025692

result:

ok 4 tokens

Test #26:

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

input:

4
6 48976172
6 4
6 1
2 5
1 5
2 3
5 47341555
1 5
4 1
2 3
3 4
5 47504872
5 1
5 3
2 4
2 5
5 45523046
4 1
4 5
3 4
5 2

output:

62444387
286055466
933929990
389184808

result:

ok 4 tokens

Test #27:

score: 0
Accepted
time: 917ms
memory: 15112kb

input:

4
6 47135616
3 5
1 6
1 4
1 2
3 2
4 48171807
3 1
3 2
2 4
7 46881593
5 3
4 1
1 3
7 5
5 2
1 6
2 2
1 2

output:

647945243
159077979
837172093
65

result:

ok 4 tokens

Test #28:

score: 0
Accepted
time: 1213ms
memory: 18968kb

input:

4
6 45340510
6 1
2 4
5 1
3 4
4 5
5 49475059
5 2
4 1
1 3
4 2
4 45780627
4 3
3 1
1 2
4 49033871
4 1
4 3
2 4

output:

287357295
935929856
762506483
789460951

result:

ok 4 tokens

Test #29:

score: 0
Accepted
time: 1226ms
memory: 18840kb

input:

4
6 47361583
2 6
5 1
5 3
5 6
4 2
6 49346013
5 1
1 4
6 1
5 2
6 3
85 50000000
51 44
13 20
14 9
46 70
5 13
7 34
33 16
23 58
33 30
67 13
3 70
8 33
38 42
7 44
40 58
70 31
23 26
50 27
7 79
28 68
74 44
37 76
23 84
58 62
59 58
12 65
59 57
60 66
81 83
20 45
24 72
29 70
70 1
64 73
63 47
53 23
27 44
74 19
38 6...

output:

557083956
521912976
508811400
923917013

result:

ok 4 tokens

Test #30:

score: 0
Accepted
time: 1166ms
memory: 18216kb

input:

4
4 48048505
3 2
4 1
1 2
6 45752957
4 3
6 5
1 2
2 6
6 4
7 45027209
4 1
6 4
3 2
2 1
5 7
6 7
2 45788884
2 1

output:

797762478
105794984
368141529
925907990

result:

ok 4 tokens

Extra Test:

score: 0
Extra Test Passed