QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#420754 | #961. Smol Vertex Cover | CarroT1212 | WA | 1ms | 4072kb | C++14 | 2.7kb | 2024-05-24 21:42:50 | 2024-05-24 21:42:51 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,N=507;
ll n,m,a[N],b[N],mch[N],vis[N],ans;
ld st;
vector<ll> e[N];
vector<pll> v;
mt19937 dnr(time(0));
bool hun(ll p) {
shuffle(e[p].begin(),e[p].end(),dnr);
vis[p]=1;
for (ll i:e[p]) {
ll j=mch[i];
if (!j) return vis[i]=1,mch[p]=i,mch[i]=p,1;
if (vis[j]) continue;
mch[p]=i,mch[i]=p,mch[j]=0;
if (hun(j)) return 1;
mch[i]=j,mch[j]=i,mch[p]=0;
}
return 0;
}
void fnd() {
memset(mch,0,sizeof(mch)),v.clear();
ll flg=1;
while ((clock()-st)/CLOCKS_PER_SEC<(ld)n*n*n/(500*500*500)*0.8&&flg) {
flg=ans;
for (ll i=1;i<=n;i++) if (!mch[i]) fill(vis+1,vis+n+1,0),ans+=hun(i);
flg=ans-flg;
}
for (ll i=1;i<=n;i++) if (mch[i]>i) v.pb({i,mch[i]});
}
namespace T {
const ll N=507;
ll n,ans[N];
ll dfn[N<<1],low[N<<1],co[N<<1],cnn,cno;
vector<ll> e[N<<1];
stack<ll> st;
void ini(ll _n) {
n=_n,cnn=0,cno=0;
for (ll i=1;i<=n*2;i++) dfn[i]=co[i]=0;
}
void clr() { for (ll i=1;i<=n*2;i++) e[i].clear(); }
void dda(ll x,ll a,ll y,ll b) { e[x+n*!a].pb(y+n*b); }
void add(ll x,ll a,ll y,ll b) { dda(x,a,y,b),dda(y,b,x,a); }
void del(ll x,ll a,ll y,ll b) { e[x+n*!a].pop_back(),e[y+n*!b].pop_back(); }
void tar(ll p) {
dfn[p]=low[p]=++cnn,st.push(p);
for (ll i:e[p]) {
if (!dfn[i]) tar(i),low[p]=min(low[p],low[i]);
else if (!co[i]) low[p]=min(low[p],dfn[i]);
}
if (dfn[p]==low[p]) {
cno++;
while (st.top()!=p) co[st.top()]=cno,st.pop();
co[p]=cno,st.pop();
}
}
bool sat() {
for (ll i=1;i<=n*2;i++) if (!dfn[i]) tar(i);
for (ll i=1;i<=n;i++) {
if (co[i]==co[i+n]) return 0;
ans[i]=!(co[i]<co[i+n]);
}
return 1;
}
}
bool solve() {
if (T::sat()) {
vector<ll> ans;
for (ll i=1;i<=n;i++) if (T::ans[i]) ans.pb(i);
cout<<ans.size()<<"\n";
for (ll i:ans) cout<<i<<" ";
return 1;
}
return 0;
}
void mian() {
scanf("%lld%lld",&n,&m);
for (ll i=1,x,y;i<=m;i++) scanf("%lld%lld",&x,&y),e[x].pb(y),e[y].pb(x),a[i]=x,b[i]=y;
st=clock();
fnd();
T::clr(),T::ini(n);
for (pll i:v) T::add(i.fi,0,i.se,0),T::add(i.fi,1,i.se,1);
for (ll i=1;i<=m;i++) if (mch[a[i]]!=b[i]) T::add(a[i],1,b[i],1);
if (solve()) return;
for (ll i=1;i<=n;i++) {
T::add(i,0,i,1);
if (solve()) return;
T::del(i,0,i,1);
}
cout<<"not smol\n";
}
bool ORY; int main() {
// while (1)
// int t; for (scanf("%d",&t);t--;)
mian();
cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB "<<clock()<<"ms";
return 0;
}
/*
3
5 5
1 2
2 3
3 4
4 5
1 5
3 0
5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4072kb
input:
5 5 1 2 2 3 3 4 4 5 1 5
output:
3 2 3 5
result:
ok vertex cover of size 3
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
5 10 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5 4 5
output:
not smol
result:
ok not smol
Test #3:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
3 0
output:
0
result:
ok vertex cover of size 0
Test #4:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
10 10 2 5 3 8 3 10 6 9 1 4 2 6 2 3 4 6 7 10 4 7
output:
5 3 4 5 6 10
result:
ok vertex cover of size 5
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3840kb
input:
10 20 1 9 3 6 3 7 8 9 3 8 1 4 5 10 7 10 4 6 7 9 9 10 2 7 1 6 5 8 2 9 1 7 5 7 3 10 2 6 4 10
output:
not smol
result:
wrong answer vertex cover is smol, but participant did not print it