QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#111548#4635. Graph OperationDualqwqWA 2ms3636kbC++141.8kb2023-06-07 15:58:142023-06-07 15:58:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 15:58:16]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3636kb
  • [2023-06-07 15:58:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5,M = N * N * 3;
typedef bitset<N> Set;
int n,m;
bitset<N> g[N],h[N];
struct OP{
	int a,b,c,d;
	OP(){}
	OP(const int &_a,const int &_b,const int &_c,const int &_d):
		a(_a),b(_b),c(_c),d(_d){}
};
vector<OP> opg,oph;
inline void Oper(int tp,int a,int b,int c,int d)
{
	// printf("Oper:%d %d %d %d\n",tp,a,b,c,d);
	if(tp == 0)
	{
		opg.emplace_back(a,b,c,d);
		g[a][b] = g[b][a] = g[c][d] = g[d][c] = 0;
		g[a][c] = g[c][a] = g[b][d] = g[d][b] = 1;
	}
	if(tp == 1)
	{
		oph.emplace_back(a,b,c,d);
		h[a][b] = h[b][a] = h[c][d] = h[d][c] = 0;
		h[a][c] = h[c][a] = h[b][d] = h[d][b] = 1;
	}
}
bool DoIt(int u)
{
	Set A = g[u],B = h[u];
	if(A == B) return false;
	Set C = A & (B.flip());B.flip();
	Set D = B & (A.flip());A.flip();
	// printf("pd:%d,%d\n",(int)D[0],(int)D[1]);
	int v = C._Find_first(),w = D._Find_first();
	// printf("Do:%d %d %d\n",u,v,w);
	Set P = g[w] & (g[v].flip());g[v].flip();
	Set Q = h[v] & (h[w].flip());h[w].flip();
	if(P.any()) {int t = P._Find_first();Oper(0,u,v,w,t);return true;}
	else {int t = Q._Find_first();Oper(1,u,w,v,t);return true;} 
	return false;
}
int main()
{
	cin >> n >> m;
	for(int i = 1;i <= m;i++)
	{
		int a,b;
		cin >> a >> b;
		g[a].set(b);g[b].set(a);
	}
	for(int i = 1;i <= m;i++)
	{
		int a,b;
		cin >> a >> b;
		h[a].set(b);h[b].set(a);
	}
	for(int i = 1;i <= n;i++) if(g[i].count() != h[i].count()) return puts("-1"),0;
	// DoIt(1);
	for(int i = 1;i <= n;i++)
		while(DoIt(i));
	printf("%d\n",opg.size() + oph.size());
	for(int i = 0;i < opg.size();i++)
		printf("%d %d %d %d\n",opg[i].a,opg[i].b,opg[i].c,opg[i].d);
	for(int i = (int)oph.size() - 1;i >= 0;i--)
		printf("%d %d %d %d\n",oph[i].a,oph[i].c,oph[i].b,oph[i].d);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3636kb

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
Wrong Answer
time: 2ms
memory: 3600kb

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:

8
1 2 3 2
2 2 3 1
2 1 4 1
3 5 1 5
4 6 1 6
5 5 1 1
5 1005 6 6
6 1005 1 4

result:

wrong answer Vertices must be distinct!