QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#73798 | #4635. Graph Operation | dwdyy | WA | 2ms | 3404kb | C++14 | 1.9kb | 2023-01-28 21:38:14 | 2023-01-28 21:38:15 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
int n , m ;
bitset<N>g[N],h[N];
int deg[N];
struct Ans{int a,b,c,d;};
vector<Ans>pre,suf;
void change(int opt,int a,int b,int c,int d){
if(opt==0) pre.push_back({a,b,c,d});
else suf.push_back({a,b,c,d});
if(opt==0){
g[a][b] = g[b][a] = 0 ;
g[c][d] = g[d][c] = 0 ;
g[a][c] = g[c][a] = 1;
g[b][d] = g[d][b] = 1;
}else {
h[a][b] = h[b][a] = 0 ;
h[c][d] = h[d][c] = 0 ;
h[a][c] = h[c][a] = 1;
h[b][d] = h[d][b] = 1;
}
}
int main()
{
cin >> n >> m;
for(int i=1;i<=m;i++){
int u,v;cin >> u >> v;
g[u].set(v,1);
g[v].set(u,1);
deg[u] ++ ;deg[v] ++ ;
}
for(int i=1;i<=m;i++){
int u,v;cin >> u >> v;
h[u].set(v,1);
h[v].set(u,1);
deg[u] -- ;deg[v] -- ;
}
for(int i=1;i<=n;i++) if(deg[i]!=0){
cout << -1;
return 0;
}
for(int i=1;i<=n;i++){
vector<int>gg,hh;
for(int j=1;j<=n;j++)
if(g[i][j]!=h[i][j]){
if(g[i][j]) gg.emplace_back(j);
else hh.emplace_back(j);
}
for(int j=0;j<gg.size();j++){
int v = gg[j];
int w = hh[j];
bitset<N>tmp = (g[w] ^ g[v]) & g[w];
int t = tmp._Find_first();
if(t==tmp.size()){
tmp = (h[w] ^ h[v]) & h[v];
t = tmp._Find_first();
change(1,i,w,v,t);
}else {
change(0,i,v,w,t);
}
}
}
reverse(suf.begin(),suf.end());
cout << pre.size() + suf.size() << '\n';
for(auto v:pre)
cout << v.a << ' ' << v.b << ' ' << v.c << ' ' << v.d << '\n';
for(auto v:suf)
cout << v.a << ' ' << v.c << ' ' << v.b << ' ' << v.d << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3340kb
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: 3404kb
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!