QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630813#4635. Graph OperationKevin5307RE 0ms5652kbC++231.7kb2024-10-11 20:31:302024-10-11 20:31:31

Judging History

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

  • [2024-10-11 20:31:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:5652kb
  • [2024-10-11 20:31:30]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int A[1010][1010],B[1010][1010];
vector<array<int,4>> vec;
void op(int a,int b,int c,int d)
{
	assert(A[a][b]);
	assert(A[c][d]);
	assert(!A[a][c]);
	assert(!A[b][d]);
	A[a][b]=A[c][d]=A[b][a]=A[d][c]=0;
	A[a][c]=A[b][d]=A[c][a]=A[d][b]=1;
	vec.push_back({a,b,c,d});
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		A[u][v]=A[v][u]=1;
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		B[u][v]=B[v][u]=1;
	}
	for(int i=1;i<=n;i++)
		if(accumulate(A[i]+1,A[i]+n+1,0)!=accumulate(B[i]+1,B[i]+n+1,0))
			die("-1");
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
			if(A[i][j]&&!B[i][j])
			{
				int p=-1;
				for(int x=i+1;x<=n;x++)
					if(!A[i][x]&&B[i][x])
					{
						p=x;
						break;
					}
				for(int y=1;y<=n;y++)
					if(y!=j&&A[y][p])
					{
						op(i,j,p,y);
						break;
					}
			}
	}
	cout<<sz(vec)<<'\n';
	for(auto arr:vec)
	{
		for(auto x:arr)
			cout<<x<<" ";
		cout<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5652kb

input:

4 2
1 2
3 4
1 3
2 4

output:

1
1 2 3 4 

result:

ok n=4

Test #2:

score: -100
Runtime Error

input:

6 12
1 2
3 5
4 6
1 4
1 5
1 6
2 3
2 5
2 6
3 4
3 6
4 5
1 3
2 4
5 6
1 4
1 5
1 6
2 3
2 5
2 6
3 4
3 6
4 5

output:


result: