QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165974#6414. Classical Maximization ProblemxuzhihaodedieWA 4ms15296kbC++141.5kb2023-09-05 23:50:562023-09-05 23:50:56

Judging History

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

  • [2023-09-05 23:50:56]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:15296kb
  • [2023-09-05 23:50:56]
  • 提交

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<=4*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;
	cin>>T;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	while(T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 15296kb

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
5 6
7 8
2
1 2
3 4
5 6
7 8
0
1 2
3 4
5 6
7 8

result:

wrong answer Integer parameter [name=k] equals to 5, violates the range [0, 2] (test case 2)