QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420667#961. Smol Vertex CoverAFewSunsWA 0ms3860kbC++204.1kb2024-05-24 21:01:572024-05-24 21:02:03

Judging History

你现在查看的是最新测评结果

  • [2024-05-24 21:02:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2024-05-24 21:01:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll int
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
queue<ll> q;
vector<ll> vec[1010];
ll t,n,m,head[550],cnt=0;
ll fa[550],mth[550],col[550],pre[550],dfn[550],tot=0;
ll dfnn[550],low[550],tott=0,blg[550],cntt=0,st[550],top=0;
bl ck[550];
struct node{
	ll nxt,to;
}e[250025];
void add(ll u,ll v){
	e[++cnt].nxt=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
ll find(ll x){
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
il ll get_lca(ll x,ll y){
	tot++;
	x=find(x);
	y=find(y);
	while(dfn[x]!=tot){
		dfn[x]=tot;
		x=find(pre[mth[x]]);
		if(y) swap(x,y);
	}
	return x;
}
il void blossom(ll x,ll y,ll lca){
	while(find(x)!=lca){
		pre[x]=y;
		y=mth[x];
		if(col[y]==2){
			col[y]=1;
			q.push(y);
		}
		if(find(x)==x) fa[x]=lca;
		if(find(y)==y) fa[y]=lca;
		x=pre[y];
	}
}
il bl bfs(ll x){
	fr(i,1,n) fa[i]=i;
	fr(i,1,n) col[i]=pre[i]=0;
	while(!q.empty()) q.pop();
	q.push(x);
	col[x]=1;
	while(!q.empty()){
		ll u=q.front();
		q.pop();
		go(u){
			ll v=e[i].to;
			if(find(u)==find(v)||col[v]==2) continue;
			if(!col[v]){
				col[v]=2;
				pre[v]=u;
				if(!mth[v]){
					ll now=v,lst;
					while(now){
						lst=mth[pre[now]];
						mth[now]=pre[now];
						mth[pre[now]]=now;
						now=lst;
					}
					return 1;
				}
				col[mth[v]]=1;
				q.push(mth[v]);
			}
			else{
				ll lca=get_lca(u,v);
				blossom(u,v,lca);
				blossom(v,u,lca);
			}
		}
	}
	return 0;
}
void tarjan(ll u){
	dfnn[u]=low[u]=++tott;
	st[++top]=u;
	ck[u]=1;
	fr(i,0,(ll)vec[u].size()-1){
		ll v=vec[u][i];
		if(!dfnn[v]){
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(ck[v]) low[u]=min(low[u],dfnn[v]);
	}
	if(dfnn[u]==low[u]){
		blg[u]=++cntt;
		ck[u]=0;
		while(st[top]!=u){
			blg[st[top]]=cntt;
			ck[st[top]]=0;
			top--;
		}
		top--;
	}
}
il void clr(){
	fr(i,1,n) head[i]=mth[i]=dfn[i]=0;
	cnt=tot=0;
}
int main(){
	t=1;
	while(t--){
		n=read();
		m=read();
		fr(i,1,m){
			ll u=read(),v=read();
			add(u,v);
			add(v,u);
		}
		ll ans=0;
		fr(i,1,n) if(!mth[i]) ans+=bfs(i);
		ll res=-1;
		fr(x,0,n){
			fr(i,0,n) vec[i].clear();
			fr(i,0,n) dfnn[i]=low[i]=blg[i]=ck[i]=0;
			tott=cntt=0;
			fr(u,1,n){
				go(u){
					ll v=e[i].to;
					if(u==x||v==x||u>v) continue;
					if(mth[u]&&mth[v]){
						vec[mth[u]].push_back(v);
						vec[mth[v]].push_back(v);
					}
					else if(mth[u]) vec[mth[u]].push_back(u);
					else vec[mth[v]].push_back(v);
				}
			}
			fr(i,0,n) if(!dfnn[i]) tarjan(i);
			bl pd=0;
			fr(i,1,n) if(i!=x&&mth[i]&&blg[i]==blg[mth[i]]) pd=1;
			if(!pd){
				res=x;
				break;
			}
		}
		if(res==-1) pf("not smol\n");
		else if(!res){
			writeln(ans);
			fr(i,1,n) if(mth[i]&&blg[i]<blg[mth[i]]) writesp(i);
			enter;
		}
		else{
			writeln(ans+1);
			fr(i,1,n) if(i==res||(mth[i]&&blg[i]<blg[mth[i]])) writesp(i);
			enter;
		}
		clr();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

5 5
1 2
2 3
3 4
4 5
1 5

output:

3
1 3 5 

result:

ok vertex cover of size 3

Test #2:

score: 0
Accepted
time: 0ms
memory: 3640kb

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: 3860kb

input:

3 0

output:

0


result:

ok vertex cover of size 0

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3644kb

input:

10 10
2 5
3 8
3 10
6 9
1 4
2 6
2 3
4 6
7 10
4 7

output:

not smol

result:

wrong answer vertex cover is smol, but participant did not print it