Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
哈哈,带位压缩的dfs只用了32MS!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator