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

Re:注意一下这题有个很奇葩的坑点...

Posted by 3012216040 at 2016-02-28 19:28:59 on Problem 2236
In Reply To:注意一下这题有个很奇葩的坑点... Posted by:crazyX at 2016-02-21 16:01:31
> 写并查集的find函数时,不要用递归,,会WA的,,莫名奇妙...
> int find(int x){
> 
> //	if(f[x]==x)return x;
> //	return f[x]==find(f[x]);
> 
> 	 //上面这种形式的会WA,下面两种都可以...
> 
> //	while(x!=f[x])     
> //        x=f[x];
> //    return x;
> 
> 
>  int k, j, r;
>     r = x;
>     while(r != f[r])     
>         r = f[r];      
>     k = x;        
>     while(k != r)          
>     {
>         j = f[k];        
>         f[k] = r;       
>         k = j;           
>     }
>     return r;
> }

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