QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#168033#6414. Classical Maximization ProblemxuzhihaodedieRE 256ms17208kbC++201.5kb2023-09-07 20:01:432023-09-09 16:03:55

Judging History

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

  • [2023-09-09 16:03:55]
  • 管理员手动重测该提交记录
  • 测评结果:RE
  • 用时:256ms
  • 内存:17208kb
  • [2023-09-07 20:01:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define x first
//#define y second
#define PII pair<int,int>
const int N=4e5+10;
const int mod=998244353;
vector<PII> g[N];
int vis[N];
int use[N];
vector<PII> ans;
void dfs(int x,int fa) {
	vis[x]=1;
	for(auto p:g[x]) {
		int y=p.first;
		if(!vis[y]) dfs(y,x);
	}
	int last=0;
	int f=0;
	for(auto p:g[x]) {
		if(use[p.second]) continue;
		int y=p.first;
		if(y==fa) f=p.second;
		else {
			if(!last) last=p.second;
			else {
				ans.push_back({last,p.second});
				use[last]=use[p.second]=1;
				last=0;
			}
		}
	}
	if(last&&f) {
		ans.push_back({last,f});
		use[last]=use[f]=1;
	}
}
void solve() {
	int n;
	cin>>n;
	int cnt=0;
	map<int,int> mp1,mp2;
	ans.clear();
	for(int i=1;i<=4*n;i++) g[i].clear(),use[i]=0;
	for(int i=1;i<=2*n;i++) {
		int x,y;
		cin>>x>>y;
		if(!mp1[x]) mp1[x]=++cnt;
		if(!mp2[y]) mp2[y]=++cnt;
		x=mp1[x],y=mp2[y];
		g[x].push_back({y,i});
		g[y].push_back({x,i});
		//cout<<x<<" "<<y<<endl;
	}
	for(int i=1;i<=4*n;i++) vis[i]=0;
	for(int i=1;i<=cnt;i++) {
		if(!vis[i]) {
			dfs(i,0);
		}
	}
	cout<<ans.size()<<endl;
	for(auto p:ans) cout<<p.first<<" "<<p.second<<endl;
	vector<int> v;
	for(int i=1;i<=2*n;i++) {
		if(!use[i]) {
			v.push_back(i);
		}
	}
	for(int i=0;i<v.size();i+=2) {
		cout<<v[i]<<" "<<v[i+1]<<endl;
	}
}
signed main() {
	int T=1;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T;
	while(T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 16368kb

input:

3
2
0 0
0 1
1 0
1 1
2
0 0
0 1
0 2
0 3
2
0 0
1 1
2 2
3 3

output:

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

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 191ms
memory: 16688kb

input:

10000
2
-107276936 -310501829
419434212 585811870
-65754386 -491212232
381152038 897148193
3
-474045168 493506332
299114415 540203303
165808153 983551
-506936261 -694189769
766718170 -725540031
975267148 -593051087
1
-818952276 -762387923
584023914 -612401389
6
-77701228 -266484128
659434465 6322062...

output:

0
1 2
3 4
0
1 2
3 4
5 6
0
1 2
0
1 2
3 4
5 6
7 8
9 10
11 12
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
0
1 2
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 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
0
1 2
3 4...

result:

ok ok (10000 test cases)

Test #3:

score: 0
Accepted
time: 174ms
memory: 15876kb

input:

10000
1
999855386 999580905
999342928 999615227
21
999601032 999015398
999155628 999176944
999309856 999524434
999121011 999509537
999323572 999685730
999272272 999769606
999450559 999390758
999632027 999178534
999024993 999463838
999784856 999374197
999980525 999366771
999241260 999516879
999599548...

output:

0
1 2
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 26
27 28
29 30
31 32
33 34
35 36
37 38
39 40
41 42
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 26
27 28
29 30
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 26
27 28
0
1 2
3 4
5 6
7...

result:

ok ok (10000 test cases)

Test #4:

score: 0
Accepted
time: 215ms
memory: 15920kb

input:

10000
5
999984799 999981445
999958394 999984217
999994978 999981258
999955539 999938710
999936554 999963561
999907222 999907508
999938166 999941959
999910567 999986887
999901446 999961092
999994730 999963038
5
999916115 999962400
999948250 999940355
999954204 999920844
999928148 999990369
999978118 ...

output:

0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
17 18
19 20
21 22
0
1 2
3 4
5 6
7 8
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 26
27 28
29 30
31 32
0
1 2
3 4
5 6
7 8
9 10
0
1 2
3 4
5 6
7 8
9 10
11 12
13 14
15 16
0
1 2
3 4
5 6
7 8
9 10
1...

result:

ok ok (10000 test cases)

Test #5:

score: 0
Accepted
time: 226ms
memory: 16724kb

input:

10000
1
999990146 999993828
999995909 999996353
56
999999851 999991179
999997250 999997987
999990590 999997316
999997350 999996856
999997034 999996236
999999396 999996897
999991180 999993309
999991265 999995185
999993952 999994054
999990210 999994471
999993201 999995893
999997170 999998971
999998201...

output:

0
1 2
1
111 76
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 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 ok (10000 test cases)

Test #6:

score: 0
Accepted
time: 256ms
memory: 16872kb

input:

10000
5
999999432 999999813
999999271 999999233
999999043 999999606
999999523 999999406
999999564 999999274
999999641 999999102
999999903 999999858
999999058 999999098
999999974 999999119
999999643 999999620
5
999999370 999999738
999999181 999999907
999999163 999999783
999999393 999999086
999999661 ...

output:

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

result:

ok ok (10000 test cases)

Test #7:

score: 0
Accepted
time: 155ms
memory: 16128kb

input:

10000
14
-369804569 -904204119
526374829 -824374353
-127549933 -904204119
-68608787 929413707
-68608787 -363454459
526374829 929413707
693313139 -824374353
-127549933 -726843762
526374829 -904204119
526374829 -363454459
526374829 -409731440
693313139 -726843762
693313139 929413707
-68608787 -8243743...

output:

14
10 19
28 5
11 25
26 16
14 23
4 13
18 6
17 20
24 15
9 2
21 22
7 27
12 8
3 1
20
34 9
13 24
29 30
25 27
5 16
20 36
40 6
22 39
26 33
35 15
28 32
12 21
7 38
4 17
23 37
11 18
31 2
14 19
3 8
10 1
8
7 11
8 14
10 15
2 4
13 3
6 12
9 16
5 1
1
1 2
1
2 1
34
37 44
51 63
65 3
16 22
23 38
39 52
59 15
10 31
33 40...

result:

ok ok (10000 test cases)

Test #8:

score: 0
Accepted
time: 150ms
memory: 17208kb

input:

10000
5
-536123007 813600068
870612905 -192916365
-891077277 -192916365
-169354047 -86845158
-204880568 -86845158
-909192812 -613162163
-536123007 -613162163
602684169 -613162163
-909192812 813600068
602684169 -86845158
3
-296375355 579758813
-296375355 253508589
-296375355 -927878827
267975935 -927...

output:

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

result:

ok ok (10000 test cases)

Test #9:

score: -100
Runtime Error

input:

10000
13
38708650 -400244265
805800882 -207412170
-922757982 569623504
330308285 -400244265
-922757982 193222226
330308285 -701148819
-28889088 854967427
284328781 704931219
-397379302 854967427
284328781 252366771
-699696493 -701148819
953729077 -601089169
-858131099 -701148819
-397379302 193222226...

output:

12
17 18
15 13
26 8
10 16
7 9
3 5
24 14
11 20
6 4
1 22
19 21
23 25
2 12
18
32 2
24 10
12 11
9 14
8 17
27 22
29 23
7 30
21 33
35 36
15 20
25 26
28 34
31 4
3 5
6 13
16 18
19 1
7
3 6
8 11
5 7
10 16
9 4
1 2
13 14
12 15
3
2 3
4 5
6 1
1
3 4
1 2
2
2 3
4 1
8
13 2
12 3
6 7
5 8
16 11
9 15
10 14
4 1
3
8 4
6 7
...

result: