QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#50848 | #4635. Graph Operation | Appleblue17 | WA | 2ms | 3644kb | C++14 | 1.2kb | 2022-09-29 15:20:24 | 2022-09-29 15:21:03 |
Judging History
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!