Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哈哈,带位压缩的dfs只用了32MS!

Posted by NeverWin at 2011-06-27 09:48:11 on Problem 3275
In Reply To:没天理啊!这题加了个-O2反而TLE了! Posted by:NeverWin at 2011-06-26 21:42:06
void dfs(int a){
	used[a]=1;
	for (int i=0;i<N2;i++)A[a][i]=0;
	A[a][a>>5]|=(1<<(a&31));
	for (edge *p=E[a];p;p=p->next){
		if (!used[p->e])dfs(p->e);
		for (int i=0;i<N2;i++)
			A[a][i]|=A[p->e][i];
	}
}

	for (int i=0;i<N;i++)if (!used[i])
		dfs(i);
	popcount[0]=0;
	for (int i=1;i<65536;i++)popcount[i]=popcount[i>>1]+(i&1);
	int ret=N*(N-1)/2+N;
	for (int i=0;i<N;i++)
		for (int j=0;j<N2;j++){
			ret-=popcount[A[i][j]&65535];
			ret-=popcount[(A[i][j]>>16)&65535];
		}
	printf("%d\n",ret);



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator