QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420778 | #961. Smol Vertex Cover | CarroT1212 | WA | 0ms | 3884kb | C++14 | 2.9kb | 2024-05-24 21:55:41 | 2024-05-24 21:55:49 |
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 led(ll x,ll a,ll y,ll b) { e[x+n*!a].pop_back(); }
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) { led(x,a,y,b),led(y,b,x,a); }
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();
for (pll i:v) printf(" %lld %lld\n",i.fi,i.se);
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);
for (ll i=1;i<=n;i++) if (!mch[i]) T::dda(i,0,i,0);
if (solve()) return;
for (ll i=1;i<=n;i++) if (!mch[i]) {
T::led(i,0,i,0);
T::dda(i,1,i,1);
if (solve()) return;
T::led(i,1,i,1);
T::dda(i,0,i,0);
}
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3884kb
input:
5 5 1 2 2 3 3 4 4 5 1 5
output:
1 2 3 4 not smol
result:
wrong output format Expected integer, but " 1 2" found