QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420126#961. Smol Vertex Cover_qwqUwUTL 0ms0kbC++142.9kb2024-05-24 14:47:162024-05-24 14:47:18

Judging History

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

  • [2024-05-24 14:47:18]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-24 14:47:16]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll read(){
	ll x=0,c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0' && c<='9')x=x*10 + c-'0',c=getchar();
	return x;
}
const int N=502;
int n,m,lk[N],vis[N<<1],pre[N],fa[N];
vector<int>G[N];
inline void link(int u,int v){lk[u]=v,lk[v]=u;}
inline void up(int u){if(u)up(lk[pre[u]]),link(u,pre[u]);}
inline int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
int cnt,col[N<<1];
inline int lca(int u,int v){
	++cnt;
	while(1){
		if(col[u=find(u)] == cnt)return u;
		if(u)col[u]=cnt;
		u=pre[lk[u]]; swap(u,v);
	}
}
queue<int>q;
inline void shrink(int u,int v,int p){
	while(find(u)!=p){
		pre[u]=v,v=lk[u];fa[u]=fa[v]=p;u=pre[v];
		if(vis[v] == 2)vis[v]=1,q.push(v);
	}
}
inline bool blossom(int s){
	rep(i,1,n)fa[i]=i,vis[i]=pre[i]=0;
	q=queue<int>();q.push(s);vis[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		for(auto v:G[u]){
			if(!vis[v]){
				vis[v]=2;pre[v]=u;
				if(!lk[v]){up(v);return 1;}
				vis[lk[v]]=1;q.push(lk[v]);
			}
			else if(vis[v] == 1){
				int p=lca(u,v);
				shrink(u,v,p);
				shrink(v,u,p);
			}
		}
	}
	return 0;
}
vector<int>G2[N<<1];
int dfn[N<<1],low[N<<1],tim,dcc;
inline void get(){
	rep(i,1,n)vis[i]=0;
}
stack<int,vector<int>>st;
inline void dfs(int u){
	dfn[u]=low[u]=++tim;st.push(u);vis[u]=1;
	for(auto v:G2[u]){
		if(!dfn[v]){
			dfs(v);
			low[u]=min(low[u],low[v]);
		}
		else if(vis[v])low[u]=min(low[u],dfn[v]);
	}
	if(dfn[u] == low[u]){
		++dcc;
		while(st.top() != u){
			int v=st.top();
			col[v]=dcc,vis[v]=0;
			st.pop();
		}
		st.pop();
		col[u]=dcc,vis[u]=0;
	}
}
vector<int>vec[N<<1];
inline bool make(){
	rep(i,1,n<<1)vis[i]=col[i]=0;
	rep(i,1,n<<1)if(!dfn[i])dfs(i);
	rep(i,1,n)if(col[i] == col[i+n])return 0;
	rep(i,1,n<<1)vis[i]=1;
	rep(i,1,dcc)vec[i].clear();
	rep(i,1,n<<1)vec[col[i]].pb(i);
	rep(i,1,dcc)if(vis[i]){
		for(auto v:vec[i]) vis[col[v>n?v-n:v+n]]=0;
	}
	return 1;
}
inline void solve(){
	rep(i,1,n)G[i].clear(),vis[i]=lk[i]=0;
	n=read(),m=read();
	int M=0;
	rep(i,1,m){
		int u=read(),v=read();
		G[u].pb(v),G[v].pb(u);
		if(!lk[u] && !lk[v])link(u,v),++M;
	}
	rep(i,1,n)if(!lk[i])M += blossom(i);
	rep(j,0,n){
		tim=dcc=0;
		rep(i,1,n<<1){
			dfn[i]=low[i]=0;
			G2[i].clear();
		}
		rep(i,1,n){
			if(i==j)G2[i+n].pb(i);
			else if(!lk[i])G2[i].pb(i+n);
			for(auto k:G[i]){
				if(k==lk[i])G2[i].pb(k+n);
				G2[i+n].pb(k);
			}
		}
		if(make()){
			printf("%d\n",M+(j>0));
			rep(i,1,n)if(vis[col[i]])printf("%d ",i);
			printf("\n");
			return ;
		}
	}
	printf("not smol\n");
}
int main(){
	//freopen("data.in","r",stdin);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int T=read();while(T--)solve();
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

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

output:


result: