QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#35341#961. Smol Vertex CoverFroggyguaWA 3ms3720kbC++172.4kb2022-06-15 11:36:302022-06-15 11:36:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-15 11:36:31]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3720kb
  • [2022-06-15 11:36:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 505
typedef long long ll;
mt19937 rnd(233);
int n,m,Ans,mat[N];
vector<int> G[N];
bitset<N> bk;
bool dfs(int u){
	shuffle(G[u].begin(),G[u].end(),rnd);
	bk[u]=1;
	for(auto v:G[u]){
		if(bk[mat[v]])continue;
		int t=mat[v];
		mat[u]=v,mat[v]=u,mat[t]=0;
		if(!t||dfs(t))return true;
		mat[u]=0,mat[v]=t,mat[t]=v;
	}
	return false;
}
int get_match(){
	int tot=0;
	for(int T=1;T<=5;++T){
		for(int i=1;i<=n;++i){
			if(!mat[i]){
				bk.reset();
				tot+=dfs(i);
			}
		}
	}
	return tot;
}
vector<int> H[N];
int id[N],p[N];
int dfn[N],low[N],num,tot,col[N];
bool vis[N];
inline int yes(int x){return 2*x+1;}
inline int no(int x){return 2*x;}
inline void adde(int u,int v){
	H[u].push_back(v);
	H[v^1].push_back(u^1);
}
void Clear(int n){
	for(int i=1;i<=n;++i){
		dfn[i]=low[i]=vis[i]=col[i]=0;
	}
	num=tot=0;
}
void Tarjan(int u){
	static int st[N],top;
	dfn[u]=low[u]=++num;
	vis[u]=1;
	st[++top]=u;
	for(auto v:H[u]){
		if(!dfn[v]){
			Tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(vis[v]){
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(dfn[u]==low[u]){
		int t=0;
		++tot;
		while(t^u){
			t=st[top--];
			vis[t]=0;
			col[t]=tot;
		}
	}
}
bool check(){
	Clear(n);
	for(int i=1;i<=n;++i){
		if(!dfn[i])Tarjan(i);
	}
	for(int i=1;i<=Ans;++i){
		if(col[yes(i)]==col[no(i)]){
			return false;
		}
	}
	return true;
}
void Do(int z){
	for(int i=1;i<=n;++i){
		H[i].clear();
	}
	if(id[z]){
		adde(id[z],id[z]^1);
	}
	for(int u=1;u<=n;++u){
		if(u==z)continue;
		for(auto v:G[u]){
			if(v==z)continue;
			if(!id[u]&&!id[v]){
				return;
			}
			if(!id[u]){
				adde(id[v]^1,id[v]);
			}
			else if(!id[v]){
				adde(id[u]^1,id[u]);
			}
			else{
				if((id[u]^1)==id[v])continue;
				adde(id[u]^1,id[v]);
			}
		}
	}
	if(check()){
		cout<<Ans+(z>0)<<'\n';
		if(z)cout<<z<<' ';
		for(int i=1;i<=Ans;++i){
			cout<<(col[yes(i)]<col[no(i)]?p[yes(i)]:p[no(i)])<<' ';
		}
		exit(0);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	Ans=get_match();
	for(int i=1,e=2;i<=n;++i){
		if(!mat[i]||id[i])continue;
		p[id[i]=e++]=i;
		p[id[mat[i]]=e++]=mat[i];
	}
	Do(0);
	for(int i=1;i<=n;++i){
		Do(i);
	}
	cout<<"not smol\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3552kb

input:

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

output:

3
1 5 3 

result:

ok vertex cover of size 3

Test #2:

score: 0
Accepted
time: 2ms
memory: 3612kb

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: 2ms
memory: 3648kb

input:

3 0

output:

0

result:

ok vertex cover of size 0

Test #4:

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

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
1 2 3 6 7 

result:

ok vertex cover of size 5

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3720kb

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:

6
2 1 6 7 10 9 

result:

wrong answer not a vertex cover