QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425701#961. Smol Vertex CoverKazemaruRE 5ms44932kbC++142.2kb2024-05-30 15:56:542024-05-30 15:56:54

Judging History

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

  • [2024-05-30 15:56:54]
  • 评测
  • 测评结果:RE
  • 用时:5ms
  • 内存:44932kb
  • [2024-05-30 15:56:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
inline int read(){
    int x=0;char ch=getchar();
    for(;'0'>ch||ch>'9';ch=getchar());
    for(;'0'<=ch&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);
    return x;
}
const int N=3e5;
mt19937 rd(time(NULL)^37);
struct Flametail{
	vector<int>q[N];
	int a[N],st[N],sc[N],dfn[N],low[N],vis[N],n,m,s,l;
	inline void init(int N){n=N;m=s=l=0;f(i,0,n*2+9)dfn[i]=vis[i]=st[i]=0,q[i].clear();}
	inline void add(int x,int a,int y,int b){q[x+a*n].push_back(y+b*n);}
	void tj(int x){
		vis[st[++s]=x]=1;
		dfn[x]=low[x]=++l;
		for(int y:q[x]){
			if(!dfn[y])tj(y);
			if(vis[y])low[x]=min(low[x],low[y]);
		}
		if(dfn[x]==low[x])for(++m;st[s+1]!=x;vis[st[s--]]=0)sc[st[s]]=m;
	}
	inline int clac(){
		f(i,1,n*2)if(!dfn[i])tj(i);
		f(i,1,n){
			if(sc[i]==sc[i+n])return 0;
			a[i]=sc[i]>sc[i+n]; 
		}
		return 1;
	}
}F;
struct Kazemaru{
	vector<int>q[N];int v[N],p[N];
	inline void add(int x,int y){q[x].push_back(y);q[y].push_back(x);}
	int dfs(int x){
		int z;v[x]=1;
		shuffle(q[x].begin(),q[x].end(),rd);
		for(int y:q[x])if(!p[y]){
			p[x]=y;p[y]=x;return 1;
		}
		for(int y:q[x])if(!v[z=p[y]]){
			p[x]=y;p[y]=x;p[z]=0;
			if(dfs(z))return 1;
			p[y]=z;p[z]=y;p[x]=0;
		}
		return 0;
	}
	inline int clac(int n,double T){
		auto st=clock();int m=0;
		f(i,1,n)p[i]=0;
		while(clock()-st<T*CLOCKS_PER_SEC){
			f(x,1,n)if(!p[x]){
				f(i,1,n)v[i]=0;
				m+=dfs(x);
			}
		}
		f(i,1,n)q[i].clear();
		return m;
	}
}G;
int a[N][2],b[N],c[N],u[N],v[N],w[N],x,y;
inline void chk(int z){
	F.init(s);
	f(i,1,m)if((x=u[i])!=z&&(y=v[i])!=z){
		if(b[x]+b[y]<1)exit(-1);
		if(!b[x])x=y;if(!b[y])y=x;
		F.add(b[x],!c[x],b[y],c[y]);
		F.add(b[y],!c[y],b[x],c[x]);
	}
	if(!F.clac())return;
	f(i,1,s)w[a[i][F.a[i]]]=1;w[z]=1;
	printf("%lld\n",s+(!!z));
	f(i,1,n)if(w[i])printf("%lld ",i);
	exit(0);
}
signed main(){
	cin>>n>>m;s=0;
	f(i,1,m)G.add(u[i]=read(),v[i]=read());
	G.clac(n,1.5*n*n/250000);
	f(i,1,n)b[i]=w[i]=0;
	f(i,1,n)if(i<(l=G.p[i])){
		a[++s][0]=i;a[s][1]=l;
		b[i]=b[l]=s;c[i]=0;c[l]=1;
	}
	f(i,0,n)chk(i);
	puts("not smol");
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 44884kb

input:

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

output:

3
1 2 4 

result:

ok vertex cover of size 3

Test #2:

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

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: 3ms
memory: 32644kb

input:

3 0

output:

0

result:

ok vertex cover of size 0

Test #4:

score: 0
Accepted
time: 4ms
memory: 44932kb

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
Runtime Error

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:


result: