QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#50833 | #4635. Graph Operation | Appleblue17 | WA | 3ms | 3732kb | C++14 | 1.1kb | 2022-09-29 15:11:33 | 2022-09-29 15:15:34 |
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<=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: 100
Accepted
time: 3ms
memory: 3484kb
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: 3732kb
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:
5 1 2 3 2 2 2 3 1 3 5 1 5 4 6 2 5 5 5 1 2
result:
wrong answer Vertices must be distinct!