QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#50848#4635. Graph OperationAppleblue17WA 2ms3644kbC++141.2kb2022-09-29 15:20:242022-09-29 15:21:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-29 15:21:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3644kb
  • [2022-09-29 15:20:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1100;
int n,m;
int in[N];

vector < vector <int> > ans,anss;

bitset <N> F[N],G[N];

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) F[i][i]=G[i][i]=1;
	for(int i=1;i<=m;i++){
		int u,v; cin>>u>>v;
		F[u][v]=F[v][u]=1;
		in[u]++,in[v]++;
	}
	for(int i=1;i<=m;i++){
		int u,v; cin>>u>>v;
		G[u][v]=G[v][u]=1;
		in[u]--,in[v]--;
	}
	for(int i=1;i<=n;i++)
		if(in[i]) return puts("-1"),0;
	for(int u=1;u<=n;u++){
		if(F[u]==G[u]) continue;
		int v=(F[u] & ~G[u])._Find_first();
		int w=(G[u] & ~F[u])._Find_first();
		int t=(F[w] & ~F[v])._Find_first();
		if(t<N){
			ans.push_back({u,v,w,t});
			F[u][v]=F[v][u]=0;
			F[w][t]=F[t][w]=0;
			F[u][w]=F[w][u]=1;
			F[v][t]=F[t][v]=1;
		}
		else{
			t=(F[v] & ~G[w])._Find_first();
			anss.push_back({u,v,w,t});
			G[u][v]=G[v][u]=1;
			G[w][t]=G[t][w]=1;
			G[u][w]=G[w][u]=0;
			G[v][t]=G[t][v]=0;
		}
	}
	cout<<ans.size()+anss.size()<<'\n';
	for(int i=0;i<(int)ans.size();i++) cout<<ans[i][0]<<" "<<ans[i][1]<<" "<<ans[i][2]<<" "<<ans[i][3]<<'\n';
	for(int i=(int)anss.size()-1;i>=0;i--) cout<<anss[i][0]<<" "<<anss[i][1]<<" "<<anss[i][2]<<" "<<anss[i][3]<<'\n';
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3644kb

input:

4 2
1 2
3 4
1 3
2 4

output:

2
1 2 3 3
2 3 4 3

result:

wrong answer Vertices must be distinct!