QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#947784#900. 一般图最大权匹配sserxhs#AC ✓285ms19576kbC++205.8kb2025-03-22 17:29:462025-03-22 17:29:48

Judging History

This is the latest submission verdict.

  • [2025-03-22 17:29:48]
  • Judged
  • Verdict: AC
  • Time: 285ms
  • Memory: 19576kb
  • [2025-03-22 17:29:46]
  • Submitted

answer

//这回只花了114514min就打完了。
//真好。记得多手造几组。ACM拍什么拍。 
#include "bits/stdc++.h"
using namespace std;
template<typename typC,typename typD> istream & operator>>(istream &in,pair<typC,typD> &a) {return cin>>a.first>>a.second;}
template<typename typC> istream & operator>>(istream &in,vector<typC> &a)
{
	for (auto &x:a) cin>>x;
	return cin;
}
template<typename typC,typename typD> ostream & operator<<(ostream &cout,const pair<typC,typD> &a) {return cout<<a.first<<' '<<a.second;}
template<typename typC,typename typD> ostream & operator<<(ostream &cout,const vector<pair<typC,typD>> &a)
{
	for (auto &x:a) cout<<x<<'\n';
	return cout;
}
template<typename typC> ostream & operator<<(ostream &cout,const vector<typC> &a)
{
	int n=a.size(),i;
	if (!n) return cout;
	cout<<a[0];
	for (i=1;i<n;i++) cout<<' '<<a[i];
	return cout;
}
#if !defined(ONLINE_JUDGE)&&defined(LOCAL)
#include "my_header\debug.h"
#else
#define dbg(...) ;
#define dbgn(...) ;
#endif
typedef unsigned int ui;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int N=1e6+5;
namespace weighted_blossom_tree
{
	#define d(x) (lab[x.u]+lab[x.v]-e[x.u][x.v].w*2)
	const int N=503*2;//两倍点数
	typedef long long ll;//总和大小
	typedef int T;//权值大小
	//均不允许无符号
	const T inf=numeric_limits<int>::max()>>1;
	struct Q
	{
		int u,v;
		T w;
	} e[N][N];
	T lab[N];
	int n,m=0,id,h,t,lk[N],sl[N],st[N],f[N],b[N][N],s[N],ed[N],q[N];
	vector<int> p[N];
	void upd(int u,int v) {if (!sl[v]||d(e[u][v])<d(e[sl[v]][v])) sl[v]=u;}
	void ss(int v)
	{
		sl[v]=0;
		for (int u=1;u<=n;u++) if (e[u][v].w>0&&st[u]!=v&&!s[st[u]]) upd(u,v);
	}
	void ins(int u) {if (u<=n) q[++t]=u; else for (int v:p[u]) ins(v);}
	void mdf(int u,int w)
	{
		st[u]=w;
		if (u>n) for (int v:p[u]) mdf(v,w);
	}
	int gr(int u,int v)
	{
		if ((v=find(all(p[u]),v)-p[u].begin())&1)
		{
			reverse(1+all(p[u]));
			return (int)p[u].size()-v;
		}
		return v;
	}
	void stm(int u,int v)
	{
		lk[u]=e[u][v].v;
		if (u<=n) return;
		Q w=e[u][v];
		int x=b[u][w.u],y=gr(u,x),i;
		for (i=0;i<y;i++) stm(p[u][i],p[u][i^1]);
		stm(x,v);
		rotate(p[u].begin(),y+all(p[u]));
	}
	void aug(int u,int v)
	{
		int w=st[lk[u]];
		stm(u,v);
		if (!w) return;
		stm(w,st[f[w]]);
		aug(st[f[w]],w);
	}
	int lca(int u,int v)
	{
		for (++id;u|v;swap(u,v))
		{
			if (!u) continue;
			if (ed[u]==id) return u;
			ed[u]=id;//??????????v?? 这是原作者的注释,我也不知道是啥
			if (u=st[lk[u]]) u=st[f[u]];
		}
		return 0;
	}
	void add(int u,int a,int v)
	{
		int x=n+1,i,j;
		while (x<=m&&st[x]) ++x;
		if (x>m) ++m;
		lab[x]=s[x]=st[x]=0;lk[x]=lk[a];
		p[x].clear();p[x].push_back(a);
		for (i=u;i!=a;i=st[f[j]]) p[x].push_back(i),p[x].push_back(j=st[lk[i]]),ins(j);//复制,改一处
		reverse(1+all(p[x]));
		for (i=v;i!=a;i=st[f[j]]) p[x].push_back(i),p[x].push_back(j=st[lk[i]]),ins(j);
		mdf(x,x);
		for (i=1;i<=m;i++) e[x][i].w=e[i][x].w=0;
		memset(b[x]+1,0,n*sizeof b[0][0]);
		for (int u:p[x])
		{
			for (v=1;v<=m;v++) if (!e[x][v].w||d(e[u][v])<d(e[x][v])) e[x][v]=e[u][v],e[v][x]=e[v][u];
			for (v=1;v<=n;v++) if (b[u][v]) b[x][v]=u;
		}
		ss(x);
	}
	void ex(int u)  // s[u] == 1
	{
		for (int x:p[u]) mdf(x,x);
		int a=b[u][e[u][f[u]].u],r=gr(u,a),i;
		for (i=0;i<r;i+=2)
		{
			int x=p[u][i],y=p[u][i+1];
			f[x]=e[y][x].u;
			s[x]=1;s[y]=0;
			sl[x]=0;ss(y);
			ins(y);
		}
		s[a]=1;f[a]=f[u];
		for (i=r+1;i<p[u].size();i++) s[p[u][i]]=-1,ss(p[u][i]);
		st[u]=0;
	}
	bool on(const Q &e)
	{
		int u=st[e.u],v=st[e.v],a;
		if(s[v]==-1)
		{
			f[v]=e.u;s[v]=1;
			a=st[lk[v]];
			sl[v]=sl[a]=s[a]=0;
			ins(a);
		}
		else if(!s[v])
		{
			a=lca(u,v);
			if (!a) return aug(u,v),aug(v,u),1;
			else add(u,a,v);
		}
		return 0;
	}
	bool bfs()
	{
		memset(s+1,-1,m*sizeof s[0]);
		memset(sl+1,0,m*sizeof sl[0]);
		h=1;t=0;
		int i,j;
		for (i=1;i<=m;i++) if (st[i]==i&&!lk[i]) f[i]=s[i]=0,ins(i);
		if (h>t) return 0;
		while (1)
		{
			while (h<=t)
			{
				int u=q[h++],v;
				if (s[st[u]]!=1) for (v=1; v<=n;v++) if (e[u][v].w>0&&st[u]!=st[v])
				{
					if (d(e[u][v])) upd(u,st[v]); else if (on(e[u][v])) return 1;
				}
			}
			T x=inf;
			for (i=n+1;i<=m;i++) if (st[i]==i&&s[i]==1) x=min(x,lab[i]>>1);
			for (i=1;i<=m;i++) if (st[i]==i&&sl[i]&&s[i]!=1) x=min(x,d(e[sl[i]][i])>>s[i]+1);
			for (i=1;i<=n;i++) if (~s[st[i]]) if ((lab[i]+=(s[st[i]]*2-1)*x)<=0) return 0;
			for (i=n+1;i<=m;i++) if (st[i]==i&&~s[st[i]]) lab[i]+=(2-s[st[i]]*4)*x;
			h=1;t=0;
			for (i=1;i<=m;i++) if (st[i]==i&&sl[i]&&st[sl[i]]!=i&&!d(e[sl[i]][i])&&on(e[sl[i]][i])) return 1;
			for (i=n+1;i<=m;i++) if (st[i]==i&&s[i]==1&&!lab[i]) ex(i);
		}
		return 0;
	}
	template<typename TT> ll max_weighted_general_match(int N,const vector<tuple<int,int,TT>> &edges)//[1,n],返回权值
	{
		memset(ed+1,0,m*sizeof ed[0]);
		memset(lk+1,0,m*sizeof lk[0]);
		n=m=N;id=0;
		iota(st+1,st+n+1,1);
		int i,j;
		T wm=0;
		ll r=0;
		for (i=1;i<=n;i++) for (j=1;j<=n;j++) e[i][j]={i,j,0};
		for (auto [u,v,w]:edges) wm=max(wm,e[v][u].w=e[u][v].w=max(e[u][v].w,(T)w));
		for (i=1;i<=n;i++) p[i].clear();
		for (i=1;i<=n;i++) for (j=1;j<=n;j++) b[i][j]=i*(i==j);
		fill_n(lab+1,n,wm);
		while (bfs());
		for (i=1;i<=n;i++) if (lk[i]) r+=e[i][lk[i]].w;
		return r/2;
	}
	#undef d
}
using weighted_blossom_tree::max_weighted_general_match,weighted_blossom_tree::lk;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin>>n>>m;
	vector<tuple<int,int,long long>> edges(m);
	for (auto &[u,v,w]:edges) cin>>u>>v>>w,++u,++v;
	int cnt=0;
	ll ans=max_weighted_general_match(n,edges);
	for (int i=1;i<=n;i++) cnt+=!!lk[i];
	cout<<cnt/2<<' '<<ans<<'\n';
	for (int i=1;i<=n;i++) if (i<lk[i]) cout<<i-1<<' '<<lk[i]-1<<'\n';
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

18 120
12 10 6
13 0 10
1 0 6
8 12 5
5 14 3
2 8 1
2 11 5
7 10 1
0 7 7
7 12 2
14 12 3
6 12 10
12 5 5
8 16 5
7 3 5
5 7 10
17 12 7
16 11 2
6 11 9
0 14 2
9 17 8
12 11 2
3 0 9
13 3 7
9 2 5
14 17 9
1 15 3
16 12 3
2 17 7
17 5 2
8 5 1
5 9 7
14 13 5
7 4 1
1 6 6
14 2 7
7 9 5
12 9 10
13 6 3
13 12 2
13 2 7
4 13 ...

output:

9 81
0 16
1 2
3 10
4 13
5 7
6 11
8 17
9 12
14 15

result:

ok OK: 9 matchings (cost = 81)

Test #2:

score: 0
Accepted
time: 21ms
memory: 11828kb

input:

500 499
0 1 389813
1 2 410923
1 3 255713
2 4 863533
2 5 274010
3 6 772811
3 7 347289
4 8 199232
4 9 235314
5 10 301630
5 11 993877
6 12 84918
6 13 888477
7 14 449408
7 15 916637
8 16 961209
8 17 550509
9 18 198289
9 19 686477
10 20 468966
10 21 274223
11 22 92197
11 23 463223
12 24 408479
12 25 7559...

output:

168 119581888
0 1
2 4
3 6
5 11
7 15
8 16
9 19
10 20
12 24
13 26
14 29
17 35
18 36
22 45
23 46
25 50
27 54
28 56
31 63
32 64
33 67
34 69
37 74
38 77
39 79
40 81
41 82
42 84
43 86
44 88
47 95
48 97
49 99
51 102
52 104
53 107
55 111
57 115
58 117
59 118
60 120
61 123
62 124
66 132
71 143
72 145
73 146
...

result:

ok OK: 168 matchings (cost = 119581888)

Test #3:

score: 0
Accepted
time: 189ms
memory: 15844kb

input:

500 124750
434 328 637504
128 157 89971
332 372 614087
326 76 853539
252 296 276599
10 272 491209
0 206 155108
199 370 435246
386 330 746983
445 399 229666
134 432 295002
129 221 287033
45 495 87615
283 272 442214
216 193 945283
400 374 84291
359 187 970582
269 487 595207
136 16 753522
201 365 85346...

output:

250 249209796
0 266
1 178
2 123
3 267
4 251
5 377
6 179
7 93
8 474
9 393
10 312
11 151
12 464
13 323
14 174
15 322
16 356
17 148
18 282
19 232
20 181
21 259
22 27
23 366
24 227
25 476
26 261
28 29
30 191
31 419
32 44
33 112
34 497
35 370
36 371
37 491
38 276
39 472
40 110
41 182
42 165
43 415
45 59
...

result:

ok OK: 250 matchings (cost = 249209796)

Test #4:

score: 0
Accepted
time: 184ms
memory: 15032kb

input:

500 124750
478 344 670402
61 169 403144
226 362 582050
18 390 939395
368 496 106
167 99 320497
96 398 49834
152 153 399736
74 113 26602
194 186 182244
109 98 320637
139 65 981681
370 266 68504
370 385 563000
3 245 243216
404 418 676708
61 246 910028
230 319 359410
337 110 391826
168 405 284587
342 4...

output:

250 249190247
0 473
1 184
2 257
3 432
4 127
5 424
6 244
7 321
8 412
9 272
10 56
11 237
12 208
13 41
14 330
15 240
16 488
17 141
18 111
19 170
20 490
21 157
22 395
23 143
24 270
25 357
26 224
27 436
28 89
29 216
30 265
31 280
32 443
33 334
34 387
35 112
36 316
37 77
38 239
39 471
40 367
42 465
43 360...

result:

ok OK: 250 matchings (cost = 249190247)

Test #5:

score: 0
Accepted
time: 216ms
memory: 18540kb

input:

500 124750
69 2 176813
342 202 341146
243 316 341597
447 330 309751
67 438 255306
153 71 347111
460 431 415635
384 84 318379
309 162 533592
495 408 122486
465 385 328554
68 87 244852
307 123 261672
250 257 343542
0 321 339118
39 67 205003
203 183 393183
51 369 375752
444 251 243327
194 61 202474
288...

output:

250 124328901
0 115
1 310
2 59
3 127
4 33
5 349
6 215
7 35
8 360
9 321
10 90
11 388
12 312
13 443
14 37
15 139
16 356
17 257
18 471
19 157
20 398
21 378
22 448
23 240
24 311
25 277
26 396
27 380
28 258
29 426
30 267
31 109
32 196
34 222
36 208
38 363
39 290
40 216
41 306
42 454
43 301
44 496
45 418
...

result:

ok OK: 250 matchings (cost = 124328901)

Test #6:

score: 0
Accepted
time: 216ms
memory: 19576kb

input:

500 124750
45 342 337395
390 38 389968
231 427 391488
458 482 345244
261 81 502109
206 128 476869
255 217 408094
226 422 316251
398 427 402011
382 50 382275
40 262 255568
324 451 95299
283 367 448216
95 420 228143
269 440 386095
91 370 302609
350 70 384538
90 244 409015
8 24 348278
337 198 412958
47...

output:

250 126736851
0 137
1 416
2 208
3 329
4 31
5 282
6 58
7 112
8 188
9 173
10 204
11 474
12 35
13 296
14 146
15 269
16 470
17 478
18 175
19 181
20 381
21 362
22 158
23 202
24 211
25 483
26 372
27 268
28 401
29 392
30 391
32 404
33 182
34 165
36 449
37 218
38 67
39 193
40 101
41 123
42 283
43 117
44 407...

result:

ok OK: 250 matchings (cost = 126736851)

Test #7:

score: 0
Accepted
time: 285ms
memory: 16192kb

input:

500 124750
20 91 407687
437 222 454355
397 116 711903
362 9 138631
135 468 171177
230 328 33032
76 414 656679
96 177 265906
236 425 563563
467 208 381861
461 360 408258
131 132 374158
436 206 209585
369 190 686727
269 32 495215
317 397 713616
158 30 219580
492 196 199829
231 153 526969
448 400 40114...

output:

250 135131415
0 329
1 416
2 499
3 188
4 105
5 487
6 228
7 473
8 321
9 417
10 465
11 54
12 235
13 84
14 449
15 152
16 175
17 132
18 481
19 123
20 386
21 442
22 430
23 209
24 112
25 490
26 394
27 95
28 323
29 164
30 387
31 339
32 457
33 326
34 68
35 286
36 144
37 43
38 415
39 309
40 268
41 45
42 354
4...

result:

ok OK: 250 matchings (cost = 135131415)

Test #8:

score: 0
Accepted
time: 283ms
memory: 16044kb

input:

500 124750
139 359 560822
416 164 355940
277 289 645310
247 229 308112
254 354 413387
325 201 345965
202 138 421169
0 96 326684
219 473 180133
313 271 613276
260 320 360483
311 78 280971
358 384 638695
276 89 220497
172 199 219619
363 214 462428
221 160 345988
457 100 364383
210 335 411879
408 127 1...

output:

250 137768547
0 33
1 344
2 400
3 216
4 167
5 489
6 55
7 367
8 434
9 77
10 140
11 16
12 154
13 272
14 306
15 296
17 130
18 28
19 341
20 366
21 134
22 94
23 76
24 456
25 418
26 43
27 67
29 468
30 267
31 89
32 392
34 351
35 124
36 209
37 394
38 95
39 145
40 326
41 412
42 165
44 139
45 213
46 329
47 69
...

result:

ok OK: 250 matchings (cost = 137768547)

Test #9:

score: 0
Accepted
time: 22ms
memory: 13000kb

input:

500 509
28 29 798142
374 375 155108
465 466 67462
224 203 78421
427 428 473747
210 211 132772
244 245 365182
411 412 72018
14 15 755952
323 324 574820
6 7 550509
398 399 497268
246 247 911757
191 192 401127
92 93 735209
280 281 3728
329 330 149889
211 229 837178
395 396 128721
261 262 665820
80 81 5...

output:

229 143163175
0 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
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
56 57
58 59
60 61
62 63
64 89
65 66
67 68
70 71
72 73
74 75
76 77
78 79
80 81
83 84
85 86
87 88
90 152
92 93
95 96
97 98
99 100
101 10...

result:

ok OK: 229 matchings (cost = 143163175)

Test #10:

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

input:

7 8
2 0 1
0 5 2
5 6 3
6 1 4
1 0 5
1 3 6
3 4 7
1 4 8

output:

3 15
0 1
3 4
5 6

result:

ok OK: 3 matchings (cost = 15)

Test #11:

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

input:

4 3
0 2 1
1 3 1
1 2 3

output:

1 3
1 2

result:

ok OK: 1 matchings (cost = 3)

Test #12:

score: 0
Accepted
time: 49ms
memory: 14760kb

input:

500 18491
0 41 255713
0 42 863533
0 43 274010
0 44 772811
0 45 347289
0 46 199232
0 47 235314
0 48 301630
0 49 993877
0 50 84918
0 51 888477
0 52 449408
0 53 916637
0 54 961209
0 55 550509
0 56 198289
0 57 686477
0 58 468966
0 59 274223
0 60 92197
0 61 463223
0 62 408479
0 63 755952
0 64 992057
0 65...

output:

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

result:

ok OK: 246 matchings (cost = 236805997)

Test #13:

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

input:

14 17
0 1 1
2 3 1
4 5 1
6 7 1
8 9 1
10 11 1
1 3 1
7 9 1
0 13 1
6 12 1
1 2 1
3 4 1
0 6 1
7 8 1
9 10 1
5 13 1
11 12 1

output:

7 7
0 6
1 2
3 4
5 13
7 8
9 10
11 12

result:

ok OK: 7 matchings (cost = 7)

Test #14:

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

input:

100 4782
1 0 836156
0 2 650307
3 0 919221
4 0 949862
5 0 698275
0 6 852060
7 0 969823
0 8 976873
9 0 920939
0 10 961872
11 0 792805
12 0 783792
13 0 847080
14 0 966134
0 15 620555
16 0 660641
0 17 698789
0 18 839783
19 0 840533
20 0 803432
21 0 936205
0 22 597688
0 23 790583
24 0 807247
25 0 768673
...

output:

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

result:

ok OK: 50 matchings (cost = 48814559)

Test #15:

score: 0
Accepted
time: 88ms
memory: 14672kb

input:

500 17707
328 434 346246
157 128 880874
372 332 491081
326 76 447517
252 296 631603
272 10 529316
206 0 904903
199 370 7430
386 330 834552
445 399 672655
432 134 47985
129 221 925946
495 45 10646
272 283 805709
216 193 654458
374 400 102357
359 187 276657
269 487 309604
16 136 588531
201 365 218178
...

output:

250 244194530
0 283
1 92
2 375
3 306
4 176
5 315
6 349
7 236
8 311
9 143
10 354
11 372
12 312
13 327
14 65
15 496
16 355
17 18
19 393
20 206
21 486
22 114
23 330
24 377
25 370
26 235
27 460
28 449
29 142
30 232
31 252
32 416
33 151
34 191
35 118
36 57
37 251
38 275
39 471
40 145
41 396
42 257
43 414...

result:

ok OK: 250 matchings (cost = 244194530)

Test #16:

score: 0
Accepted
time: 219ms
memory: 13400kb

input:

500 69830
478 344 670402
61 169 403144
226 362 582050
18 390 939395
368 496 106
167 99 320497
96 398 49834
152 153 399736
74 113 26602
194 186 182244
109 98 320637
139 65 981681
370 266 68504
370 385 563000
3 245 243216
404 418 676708
61 246 910028
230 319 359410
337 110 391826
168 405 284587
342 46...

output:

250 248580250
0 473
1 432
2 23
3 257
4 127
5 424
6 213
7 321
8 412
9 272
10 56
11 237
12 208
13 430
14 381
15 240
16 207
17 36
18 220
19 170
20 490
21 157
22 168
24 143
25 224
26 161
27 418
28 271
29 374
30 100
31 280
32 443
33 368
34 478
35 174
37 184
38 239
39 471
40 367
41 92
42 465
43 66
44 206
...

result:

ok OK: 250 matchings (cost = 248580250)

Test #17:

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

input:

1 0

output:

0 0

result:

ok OK: 0 matchings (cost = 0)

Test #18:

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

input:

12 45
0 9 9
10 3 8
2 6 5
6 9 1
7 4 5
8 0 5
11 2 3
9 10 3
0 2 9
10 11 3
8 10 10
1 3 7
9 4 1
6 5 9
5 9 8
9 11 10
1 5 6
1 11 6
2 3 1
7 0 6
7 9 1
7 3 8
5 0 9
11 4 9
3 8 6
5 2 4
0 10 4
7 6 5
11 3 10
8 2 8
10 6 9
8 9 3
11 6 3
0 3 2
11 7 5
10 4 5
8 6 7
9 1 1
8 5 2
1 8 5
7 10 4
5 10 9
4 6 2
4 8 2
5 7 4

output:

6 50
0 2
1 3
4 7
5 6
8 10
9 11

result:

ok OK: 6 matchings (cost = 50)

Test #19:

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

input:

7 11
5 2 10
1 4 1
3 5 8
1 5 2
1 3 8
5 6 2
0 3 7
0 1 5
2 0 4
5 0 2
2 4 6

output:

3 19
0 1
2 4
3 5

result:

ok OK: 3 matchings (cost = 19)

Test #20:

score: 0
Accepted
time: 23ms
memory: 12052kb

input:

500 693
434 328 637504
128 157 89971
332 372 614087
326 76 853539
252 296 276599
10 272 491209
0 206 155108
199 370 435246
386 330 746983
445 399 229666
134 432 295002
129 221 287033
45 495 87615
283 272 442214
216 193 945283
400 374 84291
359 187 970582
269 487 595207
136 16 753522
201 365 853460
6...

output:

208 140607212
0 30
2 213
3 362
4 330
5 315
6 214
7 401
8 72
9 452
13 406
14 380
15 156
16 136
18 53
19 274
20 265
22 397
25 164
26 237
27 279
29 257
31 85
32 497
33 478
34 461
35 392
36 386
37 150
38 188
39 104
40 446
42 91
44 414
45 465
46 147
47 348
48 210
49 409
50 354
51 432
54 223
55 119
56 473...

result:

ok OK: 208 matchings (cost = 140607212)

Test #21:

score: 0
Accepted
time: 16ms
memory: 14108kb

input:

500 198
478 344 670402
61 169 403144
226 362 582050
18 390 939395
368 496 106
167 99 320497
96 398 49834
152 153 399736
74 113 26602
194 186 182244
109 98 320637
139 65 981681
370 266 68504
370 385 563000
3 245 243216
404 418 676708
61 246 910028
230 319 359410
337 110 391826
168 405 284587
342 467 ...

output:

115 69723351
0 71
2 271
3 176
4 438
5 340
6 52
13 166
16 417
17 467
18 390
24 448
27 236
28 146
29 268
34 53
36 424
39 63
40 287
44 159
45 269
47 332
48 379
50 175
56 257
58 484
61 246
64 442
65 227
67 149
72 91
77 148
79 396
80 337
82 441
86 290
87 482
88 130
89 183
90 487
94 450
96 186
97 134
99 4...

result:

ok OK: 115 matchings (cost = 69723351)

Test #22:

score: 0
Accepted
time: 10ms
memory: 13216kb

input:

500 88
281 268 424379
393 269 569773
293 112 820473
154 69 556134
172 56 555523
254 72 988419
231 355 399670
445 197 657413
365 320 505284
228 426 6938
475 392 572337
448 167 59585
395 239 326937
38 398 830787
407 181 29235
109 137 810927
286 132 637780
471 425 91601
241 261 565168
307 177 54898
232...

output:

70 35935997
4 290
12 118
16 121
19 81
20 305
24 45
25 275
36 307
37 427
38 398
41 457
42 268
50 277
55 205
56 172
58 220
59 369
63 158
69 154
71 350
72 254
74 481
77 351
88 345
89 306
91 342
97 419
98 415
107 363
109 137
112 293
119 200
120 410
123 221
132 286
151 232
160 421
167 448
168 276
170 396...

result:

ok OK: 70 matchings (cost = 35935997)

Test #23:

score: 0
Accepted
time: 28ms
memory: 13688kb

input:

500 1217
328 387 666424
250 126 238859
199 140 793606
383 409 328902
91 466 815857
368 268 832378
204 165 119357
276 65 25913
24 332 675150
314 385 955116
145 270 784426
72 238 210996
448 162 145634
263 269 60681
197 438 448379
478 83 910787
178 375 590129
143 296 645764
185 184 208561
463 411 73770...

output:

236 176065026
0 359
1 91
2 351
3 56
4 74
5 496
6 391
7 392
8 53
9 316
10 271
11 88
12 142
13 456
14 390
15 439
16 267
17 20
18 373
19 105
21 450
23 406
24 421
25 70
26 375
27 479
28 335
29 199
30 312
31 126
32 46
33 254
34 251
35 107
36 469
37 96
38 216
39 367
40 274
41 449
42 278
44 464
45 279
47 2...

result:

ok OK: 236 matchings (cost = 176065026)

Test #24:

score: 0
Accepted
time: 22ms
memory: 13140kb

input:

500 532
391 107 385798
204 138 601057
231 468 613601
76 171 107831
100 401 518399
409 28 566973
153 401 96171
284 46 816233
37 472 585755
347 385 828772
146 205 553619
28 126 454201
220 136 233919
7 301 545967
202 13 323656
37 222 947061
394 329 365417
174 175 931822
26 294 67332
223 265 147197
23 2...

output:

192 125667090
0 187
3 61
4 366
5 327
7 391
8 207
9 364
10 421
11 304
12 396
13 197
14 340
15 356
17 169
18 446
20 221
21 325
23 213
24 490
25 422
26 294
27 306
28 441
29 202
30 479
31 134
32 352
33 418
34 45
37 222
38 85
39 380
40 137
41 116
42 392
46 284
47 165
48 93
49 374
50 246
51 322
52 438
53 ...

result:

ok OK: 192 matchings (cost = 125667090)