QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#425683#961. Smol Vertex CoverKazemaruRE 0ms0kbC++142.3kb2024-05-30 15:46:372024-05-30 15:46:37

Judging History

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

  • [2024-05-30 15:46:37]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-05-30 15:46:37]
  • 提交

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=2020;
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 int chk(int z){
	if(z&&b[z])return 0;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 0;
	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);
	puts("");return 1;
} 
inline void doing(){
	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)if(chk(i))return;
	puts("not smol");
}
signed main(){
	int t;
	cin>>t;
	while(t--)doing();
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

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

output:


result: