QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90301#5208. Jumbled TreeslijunyiWA 53ms5900kbC++232.5kb2023-03-22 17:09:312023-03-22 17:09:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-22 17:09:32]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:5900kb
  • [2023-03-22 17:09:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=5000;
int n,m,mod;
int tot=1,pre[maxn],son[maxn],now[maxn],id[maxn],w[maxn];
int dep[maxn],fa[maxn],upv[maxn],vis[maxn],kd[maxn];
int bs=-1,sum,Fa[maxn],siz[maxn],ss[maxn],ww[maxn];
vector<int> S,T,G[maxn];
vector<pair<int,vector<int> > > ans;
int find(int x){return x==Fa[x]?x:Fa[x]=find(Fa[x]);}
void put(int x,int y,int z)
{
	pre[++tot]=now[x];
	now[x]=tot;
	son[tot]=y;
	id[tot]=z;
}
void add(int p,int q,int v)
{
	sum=(sum+v)%mod;
	T.clear();T.push_back(q);
	for(auto t:S)
		if(t!=p)
			T.push_back(t);
	sort(T.begin(),T.end());
	ans.emplace_back(v,T);
}
int power(int x,int y)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=1ll*ans*x%mod;
		y>>=1;
		x=1ll*x*x%mod;
	}
	return ans;
}
void merge(int x,int y)
{
	if(find(x)==find(y))
		return ;
	G[x].push_back(y),G[y].push_back(x);
	x=find(x),y=find(y);
	Fa[x]=y,siz[y]+=siz[x],(ss[y]+=ss[x])%=mod;
}
void dfs1(int x,int ff,int pp)
{
	fa[x]=ff;dep[x]=dep[ff]+1;
	for(int p=now[x];p;p=pre[p])
	{
		if(p==(pp^1))
			continue;
		int t=son[p];
		if(dep[t])
		{
			if(dep[t]<dep[x])
			{
				kd[id[p]]=1;
				int l=x;
				while(l!=t)
					vis[l]=1,merge(id[p],upv[l]),l=fa[l];
			}
			continue;
		}
		upv[t]=id[p],siz[id[p]]=1;
		S.push_back(id[p]);
		dfs1(t,x,p);
		if(!vis[t])
		{
			if(bs==-1)
				bs=w[id[p]];
			else if(bs!=w[id[p]])
			{
				puts("-1");
				exit(0);
			}
			
		}
	}
}
void dfs2(int x,int fa)
{
	for(auto t:G[x])
		if(t!=fa)
		{
			dfs2(t,x);
			if(kd[x])
				add(t,x,(bs-w[t]+mod)%mod),w[x]=(0ll+w[x]-bs+w[t]+mod)%mod,w[t]=bs;
			else
				add(x,t,w[t]),w[x]=(w[x]+w[t])%mod,w[t]=0;
		}
}
int main()
{
	scanf("%d%d%d",&n,&m,&mod);
	int s=0;
	for(int i=1,u,v;i<=m;i++)
		scanf("%d%d%d",&u,&v,&w[i]),put(u,v,i),put(v,u,i),s=(s+w[i])%mod,Fa[i]=i,ss[i]=w[i];
	dfs1(1,0,0);
	if(bs==-1)
		for(int i=1;i<=m;i++)
			if(i==Fa[i]&&siz[i]%mod!=0)
				bs=1ll*ss[i]*power(siz[i],mod-2)%mod;
	if(bs==-1)
	{
		for(int i=1;i<=m;i++)
			ww[i]=w[i];
		for(int i=1;i<=m;i++)
			if(i==Fa[i])
			{
				dfs2(i,0),bs=(mod-w[i])%mod;
				break;
			}
		for(int i=1;i<=m;i++)
			w[i]=ww[i];
		ans.clear();
	}
	for(int i=1;i<=m;i++)
		if(i==Fa[i])
		{
			dfs2(i,0);
			if(w[i]!=(1-kd[i])*bs)
				return puts("-1"),0;
		}
	add(*S.begin(),*S.begin(),(bs-sum+mod)%mod);
	printf("%d\n",(int)ans.size());
	for(auto [x,y]:ans)
	{
		printf("%d ",x);
		for(auto t:y)
			printf("%d ",t);
		puts("");
	}
	
	return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3756kb

input:

3 3 101
1 2 30
2 3 40
3 1 50

output:

3
20 1 3 
10 1 2 
30 2 3 

result:

ok Participant found an answer (3 trees) and jury found an answer (5 trees)

Test #2:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

2 2 37
1 2 8
1 2 15

output:

2
8 1 
15 2 

result:

ok Participant found an answer (2 trees) and jury found an answer (3 trees)

Test #3:

score: 0
Accepted
time: 2ms
memory: 3688kb

input:

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

output:

-1

result:

ok Both jury and participant did not find an answer

Test #4:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

10 15 997
4 3 459
9 7 94
9 8 767
10 2 877
5 8 258
3 4 166
8 5 621
8 10 619
9 1 316
10 5 516
3 10 125
1 7 961
3 6 500
4 10 976
3 4 842

output:

-1

result:

ok Both jury and participant did not find an answer

Test #5:

score: 0
Accepted
time: 2ms
memory: 3904kb

input:

20 30 9973
1 10 696
3 8 2905
12 7 6609
20 10 1962
11 9 8430
19 2 412
6 3 6936
19 7 9113
14 15 5635
15 7 1770
13 10 3182
3 16 2625
17 1 7387
11 5 3700
9 15 1048
2 3 7717
12 10 8625
7 13 8141
5 14 2245
6 4 2819
18 19 8709
18 5 6191
17 10 7606
9 20 8626
17 4 8848
4 13 1073
10 8 2277
14 2 7714
11 8 5318...

output:

30
666 4 6 7 10 12 13 14 15 16 17 18 22 24 25 26 27 28 29 30 
7605 4 6 7 8 12 13 14 15 16 17 18 21 24 25 26 27 28 29 30 
1508 4 7 8 10 12 13 14 15 16 17 18 21 24 25 26 27 28 29 30 
7455 4 7 10 12 13 14 15 16 17 18 21 22 24 25 26 27 28 29 30 
8043 4 6 7 10 12 13 14 15 17 18 21 22 24 25 26 27 28 29 30...

result:

ok Participant found an answer (30 trees) and jury found an answer (59 trees)

Test #6:

score: 0
Accepted
time: 1ms
memory: 3780kb

input:

50 80 99991
6 5 67664
39 4 74944
11 9 13035
13 48 81979
40 20 57943
20 31 72081
1 6 39307
48 39 3550
28 48 41071
18 28 42935
37 32 7538
37 29 3815
50 37 88043
38 41 7283
40 26 66278
37 34 60696
47 19 80875
4 26 67
20 32 91858
39 24 83485
45 25 12241
48 46 61691
37 44 47541
39 40 70034
37 42 25006
27...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #7:

score: 0
Accepted
time: 2ms
memory: 3568kb

input:

100 150 999983
84 10 999545
69 48 930138
48 13 303468
36 6 668122
91 84 115623
62 71 59711
12 37 749281
86 49 281976
26 46 624831
91 8 450475
92 55 460900
50 63 513056
72 2 477622
26 96 11359
31 82 953946
6 71 406339
24 7 177090
70 4 67359
31 39 795565
47 32 407459
26 35 760698
22 37 508175
8 93 612...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #8:

score: 0
Accepted
time: 2ms
memory: 3772kb

input:

200 250 9999991
170 185 3242943
70 17 6083198
137 55 4000889
15 171 1113989
108 65 7988488
192 37 8812990
53 143 8707264
80 180 2504807
55 163 2706048
67 64 6210980
87 165 7693967
155 122 8550804
56 99 7228534
114 138 7047731
190 196 6684929
86 197 8866886
38 195 6717874
112 133 7257617
160 104 3210...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #9:

score: 0
Accepted
time: 2ms
memory: 3704kb

input:

500 600 99999989
265 416 47066772
354 266 16969437
195 415 7917612
354 136 43128175
163 191 58723996
144 84 65835385
157 45 94124747
232 441 17509499
70 397 64101208
223 387 7043647
320 47 84970673
100 2 87310855
87 131 75042257
101 391 27645446
79 26 68547739
390 185 92142961
257 15 80922292
276 48...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #10:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

500 700 99999989
250 2 71289880
454 447 70661327
328 253 57519343
11 201 67456781
294 99 23392419
215 322 61059212
411 389 69899684
488 429 89579827
437 79 60564061
413 380 34922641
477 372 14858185
156 44 3101349
88 8 52225146
115 26 8582010
171 237 33206748
237 495 31192017
146 32 62712576
209 352...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #11:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

500 800 99999989
258 304 1237432
159 152 6684056
8 47 64155938
436 265 83092505
204 302 3892712
142 302 77925167
37 15 20298972
202 395 35856655
284 260 96812598
365 172 48834835
196 101 64871741
174 45 37729972
302 206 90932677
305 275 27712443
443 157 81820535
16 248 22708463
461 479 64749118
105 ...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #12:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

500 900 99999989
122 188 44796717
73 121 56798468
334 358 95823235
485 453 96779071
209 391 45946094
332 168 91056077
481 483 81268636
148 393 25213027
107 214 99281713
493 46 61525618
472 355 74320568
258 482 99615552
159 393 20311839
411 121 5207095
20 131 65269699
45 339 51772607
195 292 64556504...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #13:

score: 0
Accepted
time: 2ms
memory: 3624kb

input:

500 1000 99999989
75 20 25003980
292 19 89418683
353 246 74910681
183 201 97535184
254 421 50614221
15 396 86624029
82 13 67776336
86 70 62843451
279 3 55801636
29 425 30024776
176 243 16631048
498 363 77415492
55 305 80862521
213 110 30693079
432 358 99667002
201 30 44433122
97 203 16284993
118 490...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #14:

score: 0
Accepted
time: 2ms
memory: 3700kb

input:

500 499 999999937
287 228 350409600
392 107 350409600
458 22 350409600
362 425 350409600
368 136 350409600
364 71 350409600
211 265 350409600
167 116 350409600
195 353 350409600
489 477 350409600
380 85 350409600
281 15 350409600
263 247 350409600
453 122 350409600
104 187 350409600
331 223 35040960...

output:

1
350409600 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

result:

ok Participant found an answer (1 trees) and jury found an answer (1 trees)

Test #15:

score: 0
Accepted
time: 2ms
memory: 4128kb

input:

500 510 999999937
417 280 770450784
207 303 770450784
472 396 770450784
345 191 964169440
164 67 770450784
492 302 770450784
5 71 770450784
386 22 770450784
77 25 487491058
430 467 770450784
148 95 770450784
288 215 770450784
55 451 10190666
215 69 770450784
267 195 770450784
487 283 770450784
435 3...

output:

129
285922045 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 10...

result:

ok Participant found an answer (129 trees) and jury found an answer (257 trees)

Test #16:

score: 0
Accepted
time: 12ms
memory: 4176kb

input:

500 525 999999937
439 54 982774700
417 443 87702331
21 82 982774700
39 477 982774700
363 493 982774700
500 161 982774700
86 44 982774700
312 47 982774700
120 282 982774700
224 254 670954686
268 311 59221562
216 242 982774700
16 256 505585800
448 102 982774700
362 295 555877345
76 210 819076841
53 24...

output:

198
113485603 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 28 29 30 31 32 33 34 35 36 37 38 39 40 41 43 44 45 46 47 48 49 50 51 53 54 55 56 58 59 60 61 62 63 64 65 67 68 69 71 72 73 74 75 76 77 78 79 80 82 83 85 86 87 88 89 90 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 ...

result:

ok Participant found an answer (198 trees) and jury found an answer (395 trees)

Test #17:

score: 0
Accepted
time: 18ms
memory: 4360kb

input:

500 550 999999937
478 408 544946602
494 234 544946602
118 11 544946602
497 38 435997116
193 371 493919798
252 238 826125135
69 229 683109191
300 159 544946602
328 102 302951499
37 227 568031903
347 13 544946602
111 375 624947749
291 447 544946602
5 140 544946602
250 41 544946602
387 202 544946602
38...

output:

309
955260112 1 2 3 4 5 8 9 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 50 51 52 53 54 55 57 58 59 60 61 62 63 65 66 67 68 70 71 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 101 102 104 105 107 108 10...

result:

ok Participant found an answer (309 trees) and jury found an answer (617 trees)

Test #18:

score: 0
Accepted
time: 17ms
memory: 4588kb

input:

500 600 999999937
265 416 960325147
354 266 501849515
195 415 308033318
354 136 658703469
163 191 792878874
144 84 388345161
157 45 308033318
232 441 175503107
70 397 520297316
223 387 650583946
320 47 790017725
100 2 477058566
87 131 953737746
101 391 308033318
79 26 941025744
390 185 519333525
257...

output:

406
276463243 1 2 3 4 6 7 12 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 35 36 37 39 42 43 44 45 47 49 50 51 52 54 56 57 58 59 61 62 64 66 67 68 69 70 71 72 73 74 75 77 78 80 81 83 84 86 88 89 90 91 92 93 94 96 97 98 99 100 101 102 103 104 105 106 107 108 111 114 115 116 117 118 119 121 123 1...

result:

ok Participant found an answer (406 trees) and jury found an answer (811 trees)

Test #19:

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

input:

500 500 999999937
56 278 340955979
53 151 340955979
482 317 340955979
4 138 340955979
454 135 340955979
482 361 340955979
85 89 340955979
436 201 340955979
450 483 340955979
274 258 340955979
13 318 340955979
87 227 340955979
141 114 340955979
284 340 340955979
377 48 340955979
110 134 340955979
271...

output:

13
990007591 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99...

result:

ok Participant found an answer (13 trees) and jury found an answer (25 trees)

Test #20:

score: 0
Accepted
time: 33ms
memory: 4988kb

input:

500 700 999999937
250 2 231570738
454 447 348559779
328 253 557290971
11 201 742990307
294 99 355194759
215 322 346919021
411 389 223497390
488 429 924302863
437 79 634119443
413 380 194151871
477 372 634119443
156 44 723189726
88 8 656811915
115 26 494639245
171 237 579262439
237 495 225519328
146 ...

output:

607
863517545 1 6 7 8 9 10 11 13 16 17 21 22 25 27 28 30 31 34 36 37 38 39 41 42 43 45 46 47 49 50 51 52 56 57 58 59 60 66 67 68 69 70 71 73 74 77 78 79 82 84 86 87 90 91 93 94 95 96 97 99 100 101 102 103 106 107 108 109 113 114 117 118 119 122 123 124 126 127 129 130 131 132 133 134 135 142 143 144...

result:

ok Participant found an answer (607 trees) and jury found an answer (1213 trees)

Test #21:

score: 0
Accepted
time: 19ms
memory: 5268kb

input:

500 800 999999937
258 304 583150933
159 152 864655622
8 47 904254153
436 265 649209189
204 302 999927615
142 302 437142821
37 15 886997658
202 395 176364113
284 260 352132138
365 172 621577977
196 101 999803609
174 45 669960837
302 206 85008264
305 275 142531904
443 157 652057600
16 248 693746068
46...

output:

721
129387194 2 3 4 7 8 15 16 18 22 23 24 26 27 31 32 36 39 40 45 47 48 51 52 53 54 55 56 58 59 60 65 66 67 71 72 75 78 83 85 89 90 93 96 97 99 102 103 105 106 107 109 110 112 113 115 116 117 118 119 120 124 127 128 130 131 132 136 138 140 142 143 150 151 153 156 157 160 162 163 164 166 170 171 173 ...

result:

ok Participant found an answer (721 trees) and jury found an answer (1441 trees)

Test #22:

score: 0
Accepted
time: 44ms
memory: 5520kb

input:

500 900 999999937
122 188 437691348
73 121 296323029
334 358 25382116
485 453 71271129
209 391 955537437
332 168 58669489
481 483 584529141
148 393 88230539
107 214 706736962
493 46 995301637
472 355 754703158
258 482 416475555
159 393 775800573
411 121 458973126
20 131 939950122
45 339 247694299
19...

output:

851
637054259 1 3 7 12 14 15 24 28 33 35 38 42 50 53 54 56 62 64 65 66 67 71 73 80 81 82 83 85 86 88 89 93 94 97 100 101 105 115 117 118 119 121 123 124 125 128 130 133 136 137 142 147 149 153 155 158 159 160 164 165 171 175 177 179 185 189 193 197 200 204 206 207 209 212 219 220 221 222 226 227 232...

result:

ok Participant found an answer (851 trees) and jury found an answer (1701 trees)

Test #23:

score: 0
Accepted
time: 47ms
memory: 5880kb

input:

500 1000 999999937
75 20 857550680
292 19 110166270
353 246 190797204
183 201 150954990
254 421 374099649
15 396 837014574
82 13 802431102
86 70 422727121
279 3 985425226
29 425 742626961
176 243 571825134
498 363 619955816
55 305 797984505
213 110 284175102
432 358 702809990
201 30 28699854
97 203 ...

output:

973
788911614 8 10 21 28 29 34 36 39 46 47 50 61 64 65 68 69 70 84 85 86 87 88 90 91 94 96 98 105 114 120 123 124 135 136 137 140 144 146 147 149 150 151 153 159 166 167 169 170 175 187 188 189 192 195 198 204 205 211 218 224 226 227 228 230 232 233 234 235 237 239 244 248 255 257 258 259 261 265 26...

result:

ok Participant found an answer (973 trees) and jury found an answer (1945 trees)

Test #24:

score: 0
Accepted
time: 0ms
memory: 3920kb

input:

2 1000 999999937
1 2 411133720
1 2 776367809
1 2 801503481
2 1 289867740
2 1 639986495
2 1 555099841
2 1 689485994
1 2 108816472
2 1 877082404
1 2 123678957
2 1 880363745
1 2 770025482
1 2 593440355
2 1 899935259
1 2 157609551
2 1 373761515
2 1 2889558
2 1 629415436
1 2 684947844
1 2 485414377
2 1 4...

output:

1000
751289520 999 
600564430 998 
284024873 997 
401304129 996 
273345406 995 
466354349 994 
892501116 993 
356576402 992 
288991568 991 
535497220 990 
819016733 989 
929294871 988 
633423983 987 
475246961 986 
972029034 985 
176742041 984 
247535893 983 
529760382 982 
913223614 981 
587198213 ...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #25:

score: 0
Accepted
time: 2ms
memory: 3912kb

input:

10 1000 999999937
3 6 178912852
10 3 875510731
6 7 212989905
7 5 974004463
1 10 620941502
7 5 600081434
9 1 394370115
1 3 776909504
5 1 370501286
6 8 726447186
10 5 267613208
2 9 467291795
9 2 938683115
5 4 729586694
2 7 214781199
6 5 414875992
9 6 60215552
3 6 901637793
7 9 907537612
7 8 42123063
1...

output:

1000
690367245 904 986 989 993 996 997 998 999 1000 
144288251 904 983 986 990 993 996 997 998 1000 
432047108 904 978 986 990 993 996 997 998 1000 
206639800 904 976 986 990 993 996 997 998 1000 
421470700 904 973 986 990 993 996 997 998 1000 
684968148 904 969 986 990 993 996 997 998 1000 
6450270...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #26:

score: 0
Accepted
time: 11ms
memory: 4308kb

input:

100 1000 999999937
27 22 577129898
47 76 383040531
44 49 252504590
66 46 764432363
75 76 827756718
80 35 275529478
95 9 886404040
55 97 184978304
11 72 641255171
65 95 394679645
37 8 171252921
35 39 277250820
62 10 745905336
97 76 208239094
16 34 460397322
74 28 465442229
89 95 979433574
70 86 67725...

output:

1000
787456731 18 143 181 189 217 303 480 502 505 614 645 676 682 687 689 693 698 703 716 742 763 778 784 789 806 808 811 814 818 820 824 830 838 846 849 852 854 856 857 858 865 868 872 878 889 890 898 899 906 912 913 917 920 927 928 930 931 935 937 943 944 946 947 955 956 957 958 959 960 961 962 96...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #27:

score: 0
Accepted
time: 41ms
memory: 5788kb

input:

498 1000 999999937
487 73 269543467
331 211 379519784
495 422 686973047
284 16 204129347
254 399 260794796
422 126 211993357
166 429 802536094
351 315 235479275
49 324 904476025
55 15 317387996
440 330 833475395
398 483 245510540
283 270 881075381
392 210 101464008
462 186 116907647
183 33 19696935
...

output:

1000
322642719 2 4 5 9 14 15 25 26 30 31 36 43 44 57 58 59 64 66 68 70 74 76 77 79 82 83 84 89 90 91 95 100 106 110 111 112 119 122 124 126 128 131 134 143 145 153 154 155 157 162 165 176 178 185 187 192 193 196 197 199 207 208 210 222 224 227 234 241 245 253 256 264 265 272 277 281 283 285 289 292 ...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #28:

score: 0
Accepted
time: 53ms
memory: 5828kb

input:

499 1000 999999937
144 284 46025639
242 260 240568220
449 203 912275568
260 4 382100531
96 298 24757210
255 315 720292625
111 97 124002714
227 444 550413391
331 282 363023595
201 44 757190858
498 460 378149715
387 63 989403521
195 296 477597041
210 146 858766928
499 87 408290897
313 395 347050751
14...

output:

1000
704890804 4 5 13 14 15 20 21 23 24 29 31 33 34 36 46 47 49 50 52 54 59 65 70 71 79 80 83 85 87 90 93 94 99 102 108 112 113 119 121 125 128 133 139 141 146 147 148 151 157 159 160 161 165 174 177 179 182 186 190 192 195 199 202 208 213 214 216 220 221 222 228 238 239 240 243 250 253 256 267 269 ...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #29:

score: 0
Accepted
time: 46ms
memory: 5900kb

input:

500 1000 999999937
114 191 548698698
257 259 174101411
166 144 307067234
5 65 315189831
130 144 764747698
191 263 657349687
435 125 520510567
72 457 869051725
31 434 652697712
451 437 241147129
140 367 568108671
423 368 152200500
258 291 922031445
489 5 313644610
407 393 435155235
96 135 53577132
26...

output:

999
434542648 4 5 6 11 19 25 27 36 41 43 46 48 51 53 58 60 66 69 72 74 79 82 85 88 91 94 96 103 110 111 113 116 120 125 128 130 134 137 144 147 151 155 156 161 165 169 172 175 178 182 186 187 188 191 193 196 198 202 206 207 209 211 215 217 218 220 222 223 227 229 231 232 234 237 246 248 251 253 259 ...

result:

ok Participant found an answer (999 trees) and jury found an answer (1997 trees)

Test #30:

score: 0
Accepted
time: 4ms
memory: 3992kb

input:

10 1000 999999937
1 6 169017311
6 4 813438192
7 10 658256408
3 10 356519068
5 8 105814076
10 9 432666653
2 10 924273201
4 2 438838176
6 10 23105379
9 3 61095925
4 6 492672241
8 1 350092485
1 3 849557758
9 8 527128919
5 10 399172798
2 4 637109541
9 7 862381710
8 4 821851347
9 1 517530356
10 7 7723516...

output:

1000
922723233 968 988 989 991 993 995 998 999 1000 
854725655 968 984 988 991 995 997 998 999 1000 
250143646 968 982 988 991 995 997 998 999 1000 
382840366 968 979 988 991 995 997 998 999 1000 
385771095 968 976 988 991 995 997 998 999 1000 
784002471 967 968 988 991 995 997 998 999 1000 
2272898...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #31:

score: 0
Accepted
time: 0ms
memory: 4036kb

input:

50 1000 999999937
47 31 338993180
1 40 981131058
16 14 475599962
29 44 218651110
13 5 295788288
8 46 379702422
16 8 788369898
12 21 193552464
42 4 516953820
17 46 395588075
26 32 801052259
22 6 252241088
25 47 415361628
36 14 665366957
24 5 332323875
45 22 667496708
30 48 315574397
42 5 265997928
16...

output:

1000
732464458 430 629 742 744 752 800 805 825 847 876 888 898 906 907 914 926 929 938 944 947 948 953 954 956 957 964 968 969 970 972 973 975 976 978 980 981 982 985 986 988 989 992 993 994 996 997 998 999 1000 
323925183 430 629 742 744 752 800 805 825 847 876 888 893 898 906 914 926 929 938 947 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #32:

score: 0
Accepted
time: 18ms
memory: 4736kb

input:

200 1000 999999937
155 193 467849083
56 59 535575167
97 22 494627324
200 72 960374690
51 200 104743381
129 37 403458202
99 138 318791385
164 7 513263543
116 185 858111714
169 165 864977405
87 135 479124746
164 37 463283980
98 150 827389077
111 2 519317068
8 84 554409749
51 11 688845859
164 39 370009...

output:

1000
407483604 5 57 75 88 98 101 102 103 114 127 142 149 158 168 196 202 227 233 250 253 296 322 333 335 339 343 357 365 370 393 399 421 440 450 456 472 490 495 508 518 520 526 529 530 535 540 543 544 545 568 571 572 584 585 595 612 619 626 627 655 656 665 669 672 675 689 694 698 700 703 704 712 722...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1999 trees)

Test #33:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

499 1000 999999937
378 480 476231202
116 251 757524517
304 91 136773672
58 7 246393874
378 453 282946052
378 336 684803902
161 356 124374696
378 359 997729308
378 72 26684646
378 325 946203739
370 109 226216491
378 220 60777554
344 414 415380261
378 275 83199163
378 412 850660890
378 81 183620361
37...

output:

-1

result:

ok Both jury and participant did not find an answer

Test #34:

score: 0
Accepted
time: 48ms
memory: 5676kb

input:

500 1000 999999937
430 117 111637665
85 228 267289407
478 304 819693771
477 99 161971830
69 242 172626708
397 448 755199536
397 165 556061372
397 309 705286456
397 71 441535487
397 242 463539465
451 64 63633665
397 333 435428974
441 202 512181674
397 217 566535010
397 241 556061372
390 384 444381502...

output:

923
976715936 1 2 3 4 7 13 15 16 18 19 21 24 29 32 33 34 36 40 42 43 44 45 47 52 53 60 62 63 64 66 68 73 75 76 77 78 79 81 83 85 86 87 91 93 96 98 99 101 102 103 104 105 106 108 110 111 112 114 115 116 120 121 124 135 137 138 139 140 142 144 146 148 149 151 158 161 162 163 166 167 171 173 178 179 18...

result:

ok Participant found an answer (923 trees) and jury found an answer (1845 trees)

Test #35:

score: 0
Accepted
time: 2ms
memory: 3988kb

input:

20 1000 2
5 11 1
10 6 0
10 13 1
3 6 0
4 8 0
14 1 0
6 7 1
19 20 1
15 12 0
5 1 1
2 5 0
14 5 1
13 4 1
6 12 1
20 16 1
10 13 1
2 10 1
17 14 1
2 19 1
17 12 1
17 11 0
5 20 1
10 5 0
7 19 0
12 9 0
14 6 1
12 13 1
7 2 1
16 15 1
2 15 1
8 12 1
3 14 1
3 17 1
9 10 1
10 1 1
14 20 0
6 12 0
19 1 0
2 16 1
8 15 1
1 11 ...

output:

1000
0 915 934 951 967 973 977 979 981 982 985 986 990 993 994 996 997 998 999 1000 
0 915 934 949 951 967 973 977 979 981 982 986 990 993 994 996 997 998 999 1000 
1 915 934 946 951 967 973 977 979 981 982 986 990 993 994 996 997 998 999 1000 
1 915 934 936 951 967 973 977 979 981 982 986 990 993 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (972 trees)

Test #36:

score: 0
Accepted
time: 0ms
memory: 3916kb

input:

30 1000 3
23 24 0
4 9 1
13 14 1
19 21 1
21 10 1
16 18 2
23 5 0
17 9 0
2 19 1
2 17 0
30 27 0
26 25 1
10 30 1
8 10 1
29 9 2
28 29 2
26 12 1
10 13 2
11 20 0
23 5 0
23 22 1
25 5 2
19 9 1
17 6 0
19 8 0
17 28 0
6 21 1
8 9 2
11 4 1
15 21 1
18 16 0
23 15 0
11 18 2
4 15 2
10 9 2
6 5 2
19 7 1
24 16 1
14 1 2
4...

output:

1000
1 379 711 804 848 862 924 939 945 950 962 970 978 980 983 984 985 986 987 988 989 990 993 994 995 996 997 998 999 1000 
2 379 711 804 840 862 924 939 945 950 962 970 978 980 983 984 985 986 987 988 989 990 993 994 995 996 997 998 999 1000 
0 379 711 799 804 862 924 939 945 950 962 970 978 980 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1338 trees)

Test #37:

score: 0
Accepted
time: 6ms
memory: 3968kb

input:

40 1000 5
39 1 1
28 24 4
37 5 0
9 6 2
20 7 0
12 7 4
15 39 2
33 27 1
40 6 3
3 34 0
37 38 3
19 6 4
40 10 4
5 1 3
39 12 0
2 13 4
38 8 4
28 39 0
35 21 4
11 40 3
7 29 4
12 29 4
9 3 2
18 23 1
38 2 2
33 4 2
14 16 1
36 19 1
37 14 4
23 37 3
33 22 3
34 23 1
7 24 2
17 16 2
13 17 4
38 23 4
39 14 1
31 6 4
26 19 ...

output:

1000
3 257 381 725 807 839 849 887 900 919 925 927 940 941 942 946 948 951 960 970 971 972 973 976 977 978 980 981 982 983 986 987 991 993 995 996 997 998 999 1000 
0 257 381 725 807 839 849 887 900 919 925 927 929 940 942 946 948 951 960 970 971 972 973 976 977 978 980 981 982 983 986 987 991 993 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1573 trees)

Test #38:

score: 0
Accepted
time: 6ms
memory: 4080kb

input:

44 1000 7
27 12 0
7 41 5
16 21 1
41 28 2
19 16 5
37 7 1
33 1 4
28 36 4
2 11 1
17 14 0
11 15 2
2 20 4
34 44 2
27 43 3
20 7 3
40 2 5
28 15 3
40 5 6
30 4 0
27 24 2
26 38 3
24 26 4
19 6 6
19 18 2
31 10 0
5 19 2
29 39 5
1 44 6
3 1 1
43 28 6
34 29 5
43 8 0
20 43 1
25 23 6
38 21 6
32 27 2
20 31 3
16 11 0
3...

output:

1000
6 138 427 683 704 717 835 842 877 882 894 914 929 932 934 945 947 953 956 958 963 965 966 971 973 974 975 976 978 979 986 987 988 989 990 991 992 993 994 996 997 998 999 1000 
6 138 427 683 704 717 835 842 877 882 894 914 929 932 934 939 947 953 956 958 963 965 966 971 973 974 975 976 978 979 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1705 trees)

Test #39:

score: 0
Accepted
time: 6ms
memory: 4112kb

input:

44 1000 11
27 12 6
7 41 9
16 21 5
41 28 5
19 16 5
37 7 5
33 1 0
28 36 1
2 11 10
17 14 4
11 15 3
2 20 6
34 44 9
27 43 6
20 7 1
40 2 8
28 15 8
40 5 5
30 4 1
27 24 6
26 38 6
24 26 5
19 6 4
19 18 1
31 10 8
5 19 0
29 39 7
1 44 6
3 1 4
43 28 6
34 29 6
43 8 1
20 43 8
25 23 8
38 21 9
32 27 4
20 31 1
16 11 3...

output:

1000
9 138 427 683 704 717 835 842 877 882 894 914 929 932 934 945 947 953 956 958 963 965 966 971 973 974 975 976 978 979 986 987 988 989 990 991 992 993 994 996 997 998 999 1000 
10 138 427 683 704 717 835 842 877 882 894 914 929 932 934 939 947 953 956 958 963 965 966 971 973 974 975 976 978 979 ...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1797 trees)

Test #40:

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

input:

45 1000 2
42 1 1
13 16 1
22 25 1
20 1 1
18 11 1
42 12 1
40 7 1
33 6 1
13 18 1
39 2 1
19 30 1
10 4 1
1 45 1
16 18 1
17 41 1
21 11 1
1 7 1
1 7 1
43 22 1
45 22 1
5 18 1
30 25 1
3 16 1
37 13 1
35 39 1
6 31 1
12 22 1
28 27 1
4 29 1
45 14 1
31 26 1
39 43 1
29 10 1
42 28 1
26 16 1
6 27 1
33 22 1
8 41 1
17 ...

output:

1000
1 130 239 733 771 782 848 851 885 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 979 980 982 983 986 987 988 991 993 994 995 996 997 998 999 1000 
1 130 239 733 771 782 846 848 851 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1934 trees)

Test #41:

score: 0
Accepted
time: 2ms
memory: 4200kb

input:

45 1000 3
42 1 1
13 16 2
22 25 2
20 1 0
18 11 2
42 12 2
40 7 2
33 6 1
13 18 2
39 2 1
19 30 1
10 4 2
1 45 2
16 18 1
17 41 1
21 11 2
1 7 1
1 7 1
43 22 1
45 22 2
5 18 1
30 25 1
3 16 1
37 13 1
35 39 2
6 31 1
12 22 2
28 27 2
4 29 2
45 14 1
31 26 2
39 43 2
29 10 2
42 28 1
26 16 1
6 27 1
33 22 1
8 41 2
17 ...

output:

1000
2 130 239 733 771 782 848 851 885 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 979 980 982 983 986 987 988 991 993 994 995 996 997 998 999 1000 
2 130 239 733 771 782 846 848 851 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1932 trees)

Test #42:

score: 0
Accepted
time: 6ms
memory: 4088kb

input:

45 1000 5
42 1 2
13 16 3
22 25 1
20 1 3
18 11 3
42 12 3
40 7 3
33 6 4
13 18 4
39 2 3
19 30 4
10 4 3
1 45 2
16 18 4
17 41 3
21 11 3
1 7 4
1 7 0
43 22 2
45 22 4
5 18 0
30 25 3
3 16 3
37 13 3
35 39 3
6 31 4
12 22 3
28 27 2
4 29 2
45 14 1
31 26 2
39 43 1
29 10 3
42 28 2
26 16 2
6 27 2
33 22 4
8 41 3
17 ...

output:

1000
1 130 239 733 771 782 848 851 885 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 979 980 982 983 986 987 988 991 993 994 995 996 997 998 999 1000 
3 130 239 733 771 782 846 848 851 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1951 trees)

Test #43:

score: 0
Accepted
time: 1ms
memory: 4128kb

input:

45 1000 7
42 1 2
13 16 3
22 25 3
20 1 2
18 11 1
42 12 1
40 7 5
33 6 2
13 18 5
39 2 3
19 30 3
10 4 4
1 45 2
16 18 1
17 41 1
21 11 1
1 7 2
1 7 1
43 22 1
45 22 3
5 18 3
30 25 2
3 16 5
37 13 1
35 39 4
6 31 6
12 22 4
28 27 5
4 29 4
45 14 2
31 26 3
39 43 6
29 10 2
42 28 4
26 16 5
6 27 3
33 22 4
8 41 1
17 ...

output:

1000
6 130 239 733 771 782 848 851 885 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 979 980 982 983 986 987 988 991 993 994 995 996 997 998 999 1000 
6 130 239 733 771 782 846 848 851 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 9...

result:

ok Participant found an answer (1000 trees) and jury found an answer (1973 trees)

Test #44:

score: -100
Wrong Answer
time: 5ms
memory: 4100kb

input:

45 1000 11
42 1 3
13 16 7
22 25 6
20 1 9
18 11 7
42 12 6
40 7 4
33 6 2
13 18 9
39 2 2
19 30 7
10 4 6
1 45 7
16 18 4
17 41 6
21 11 2
1 7 7
1 7 9
43 22 5
45 22 5
5 18 8
30 25 4
3 16 4
37 13 10
35 39 1
6 31 6
12 22 2
28 27 2
4 29 2
45 14 8
31 26 5
39 43 9
29 10 3
42 28 4
26 16 6
6 27 1
33 22 5
8 41 9
1...

output:

1000
6 130 239 733 771 782 848 851 885 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 979 980 982 983 986 987 988 991 993 994 995 996 997 998 999 1000 
5 130 239 733 771 782 846 848 851 889 892 916 921 927 928 932 933 935 937 951 952 954 955 962 965 968 970 973 974 9...

result:

wrong answer Wrong value of edge 129 (1-based): expected = 5, actual = 4