QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#51062 | #4635. Graph Operation | JohnAlfnov | WA | 2ms | 3800kb | C++20 | 1.8kb | 2022-09-30 14:01:33 | 2022-09-30 14:01:33 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
bitset<1005>b1[1005],b2[1005];
int d1[1005],d2[1005];
vector<pair<pair<int,int>,pair<int,int>>>ans1,ans2;
void dstt1(int a,int b,int c,int d){
ans1.emplace_back(make_pair(a,b),make_pair(c,d));
b1[a][b]=0,b1[a][c]=1;
b1[b][a]=0,b1[b][d]=1;
b1[c][d]=0,b1[c][a]=1;
b1[d][c]=0,b1[d][b]=1;
}
void dstt2(int a,int b,int c,int d){
ans2.emplace_back(make_pair(a,b),make_pair(c,d));
b2[a][b]=1,b2[a][c]=0;
b2[b][a]=1,b2[b][d]=0;
b2[c][d]=1,b2[c][a]=0;
b2[d][c]=1,b2[d][b]=0;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i){
int u,v;
scanf("%d%d",&u,&v);
b1[u].set(v),b1[v].set(u);
++d1[u],++d1[v];
}
for(int i=1;i<=m;++i){
int u,v;
scanf("%d%d",&u,&v);
b2[u].set(v),b2[v].set(u);
++d2[u],++d2[v];
}
int flag=1;
for(int i=1;i<=n;++i)if(d1[i]!=d2[i])flag=0;
if(!flag){
puts("-1");
return 0;
}
bitset<1005>bb;
for(int i=1;i<=n;++i)bb.set(i);
while(bb.count()){
int x=bb._Find_first();
auto at=b1[x]&b2[x];
auto a1=b1[x]^at,a2=b2[x]^at;
if(!a1.count()){
for(int i=1;i<=n;++i)b1[x][i]=b1[i][x]=0;
for(int i=1;i<=n;++i)b2[x][i]=b2[i][x]=0;
bb[x]=0;
continue;
}
int u=a1._Find_first(),v=a2._Find_first();
auto aa=b1[v]^(b1[u]&b1[v]);
if(aa.count()){
int t=aa._Find_first();
dstt1(x,u,v,t);
}else{
auto aaa=b1[u]^(b1[u]&b1[v]);
aaa.reset(x);
int t=aaa._Find_first();
dstt2(x,u,v,t);
}
}
int s1=ans1.size(),s2=ans2.size();
printf("%d\n",s1+s2);
for(int i=0;i<s1;++i){
auto pp=ans1[i];
auto p1=pp.first,p2=pp.second;
printf("%d %d %d %d\n",p1.first,p1.second,p2.first,p2.second);
}
for(int i=s2-1;i>=0;--i){
auto pp=ans2[i];
auto p1=pp.first,p2=pp.second;
printf("%d %d %d %d\n",p1.first,p1.second,p2.first,p2.second);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3716kb
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: 1ms
memory: 3800kb
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:
4 1 2 3 2 2 2 3 4 3 5 4 5 4 6 5 5
result:
wrong answer Vertices must be distinct!