QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#692613 | #4635. Graph Operation | lrher | WA | 0ms | 3964kb | C++14 | 2.9kb | 2024-10-31 14:47:24 | 2024-10-31 14:47:29 |
Judging History
answer
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<bitset>
#include<vector>
#include<cstdio>
#include<random>
#include<complex>
#include<cstdlib>
#include<climits>
#include<iomanip>
#include<cstring>
#include<cassert>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
// #define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
// char buf[1<<21],*p1=buf,*p2=buf;
const long long _base=107374183;
int writetemp[40];
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;
return x;
}
inline void write(long long x)
{
int tot=(x==0);
writetemp[1]=0;
while(x) writetemp[++tot]=x%10,x/=10;
while(tot) putchar(writetemp[tot--]+'0');
putchar(' ');
return ;
}
int n,m,deg[1010];
bitset<1010> g1[1010],g2[1010],now;
struct op
{
int a,b,c,d;
};
vector<op> ans1,ans2;
vector<int> a,b;
int main()
{
// freopen("s.out","r",stdin);
// freopen("a.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
g1[u][v]=1,g1[v][u]=1;
deg[u]++,deg[v]++;
}
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
g2[u][v]=1,g2[v][u]=1;
deg[u]--,deg[v]--;
}
for(int i=1;i<=n;i++) if(deg[i]!=0) return printf("-1\n"),0;
for(int u=1;u<=n;u++)
{
a.clear(),b.clear();
for(int i=u+1;i<=n;i++)
{
if(g1[u][i]&&!g2[u][i]) a.push_back(i);
if(!g1[u][i]&&g2[u][i]) b.push_back(i);
}
for(int i=0;i<a.size();i++)
{
if((g1[a[i]]&g1[b[i]])==g1[b[i]])
{
now=(g2[a[i]]&g2[b[i]])^g2[a[i]];
int v=now._Find_first();
ans2.push_back((op){u,b[i],a[i],v});
g2[u][b[i]]=g2[b[i]][u]=g2[a[i]][v]=g2[v][a[i]]=0;
g2[u][a[i]]=g2[a[i]][u]=g2[b[i]][v]=g2[v][b[i]]=1;
continue;
}
now=(g1[a[i]]&g1[b[i]])^g1[b[i]];
int v=now._Find_first();
ans1.push_back((op){u,a[i],b[i],v});
g1[u][a[i]]=g1[a[i]][u]=g1[b[i]][v]=g1[v][b[i]]=0;
g1[u][b[i]]=g1[b[i]][u]=g1[a[i]][v]=g1[v][a[i]]=1;
for(int i=u+1;i<=n;i++) if(g1[u][i]) g1[u][i]=g1[i][u]=0;
for(int i=u+1;i<=n;i++) if(g2[u][i]) g2[u][i]=g2[i][u]=0;
}
}
printf("%d\n",ans1.size()+ans2.size());
for(int i=0;i<ans1.size();i++) printf("%d %d %d %d\n",ans1[i].a,ans1[i].b,ans1[i].c,ans1[i].d);
for(int i=ans2.size()-1;i>=0;i++) printf("%d %d %d %d\n",ans2[i].a,ans2[i].b,ans2[i].c,ans2[i].d);
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3908kb
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: 0ms
memory: 3964kb
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:
3 1 2 3 2 3 5 3 5 4 6 3 3
result:
wrong answer Vertices must be distinct!