QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#420492 | #961. Smol Vertex Cover | MEKHANE | WA | 1ms | 4012kb | C++14 | 2.2kb | 2024-05-24 19:20:32 | 2024-05-24 19:20:32 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int N=505;
int T,n,m,bh,bh1,fans,dans[N],u[N*N],vv[N*N],dy[N],vis[N];
vector<int> v[N];
mt19937 rd(time(0));
bool dfs(int x){
if(vis[x]) return 0; vis[x]=1;
for(auto dq:v[x]) if(!vis[dq]&&(!dy[dq]||dfs(dy[dq]))){dy[dq]=x,dy[x]=dq; return 1;}
return 0;
}
struct ts{
int ds,idx,ys,dfn[2*N],low[2*N],col[2*N],vis[2*N];
vector<int> e[2*N];
stack<int> st;
void ade(int x,int y){e[x].push_back(y);}
void cl(){rep(i,1,ds) e[i].clear();}
void tj(int x){
dfn[x]=low[x]=++idx,vis[x]=1,st.push(x);
for(auto dq:e[x]){
if(!dfn[dq]) tj(dq),low[x]=min(low[x],low[dq]);
else if(vis[dq]) low[x]=min(low[x],dfn[dq]);
}
if(low[x]==dfn[x]){
ys++;
while(1){
int dq=st.top(); vis[dq]=0,st.pop();
col[dq]=ys; if(dq==x) break;
}
}
}
bool cz(){
idx=ys=0;
rep(i,1,ds) dfn[i]=low[i]=col[i]=0;
rep(i,1,ds) if(!dfn[i]) tj(i);
rep(i,1,n) if(col[i]==col[i+n]) return 0;
return 1;
}
void sc(){
int ans=0; vector<int> av;
rep(i,1,n) if(col[i+n]<col[i]) ans++,av.push_back(i);
printf("%d\n",ans);
for(auto dq:av) printf("%d ",dq);
puts("");
}
}G;
void jb(){
rep(i,1,m) if(i!=bh){
if(dy[u[i]]==vv[i]) G.ade(u[i],vv[i]+n),G.ade(vv[i]+n,u[i]),G.ade(vv[i],u[i]+n),G.ade(u[i]+n,vv[i]);
else G.ade(u[i],vv[i]+n),G.ade(vv[i],u[i]+n);
}
rep(i,1,n) if(!dy[i]&&i!=bh1) G.ade(i+n,i);
}
void sol(){
rep(i,1,n) v[i].clear();
rep(i,1,m) scanf("%d",&u[i],&vv[i]),v[u[i]].push_back(vv[i]),v[vv[i]].push_back(u[i]);
fans=0;
rep(i,1,n) dans[i]=0;
rep(T,1,10){
int ans=0;
rep(i,1,n) dy[i]=0,shuffle(v[i].begin(),v[i].end(),rd);
rep(i,1,n) if(!dy[i]){rep(j,1,n) vis[j]=0; ans+=dfs(i);}
if(ans>fans){fans=ans; rep(i,1,n) dans[i]=dy[i];}
}
rep(i,1,n) dy[i]=dans[i];
G.ds=2*n,G.cl(),bh=0,jb();
if(G.cz()){G.sc(); return ;}
rep(i,1,m) if(dy[u[i]]==vv[i]){
G.cl(),bh=i,G.ade(u[i],vv[i]+n),G.ade(vv[i],u[i]+n),jb();
if(G.cz()){G.sc(); return ;}
}bh=0;
rep(i,1,n) if(!dy[i]){
G.cl(),bh1=i,G.ade(i,i+n),jb();
if(G.cz()){G.sc(); return ;}
}puts("not smol");
}
signed main(){
ios::sync_with_stdio(false);
while(scanf("%d%d",&n,&m)!=-1) sol();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4012kb
input:
5 5 1 2 2 3 3 4 4 5 1 5
output:
0 not smol
result:
wrong answer not a vertex cover