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

怎么转化成二分图亚

Posted by anne2277 at 2005-07-12 20:05:01 on Problem 1466
怎么转化成二分图亚?分为男孩和女孩,我做了,在求最大匹配,但是wa,大家是怎么转化成二分图的?

int main()
{
    while( scanf( "%d", &n ) == 1 )
    {
        int a, b[maxn];
        map< int, int >im;
        memset( g, 0, sizeof(g) );
        ans = 0;
        
        int num;
        for( int i = 0; i < n; i++ )
        {
            scanf( "%d", &a );
            getchar();getchar();getchar();
            scanf( "%d", &num );
            getchar();
            for( int i = 0; i < num; i++ )
            {
                  scanf( "%d", &b[i] );    
            }
            int flag = 0;
            for( int i = 0; i < num; i++ )
            {
                       if( im[b[i]] > 0 )
                       {
                              flag = 1;
                              break;    
                       }    
                       else if( im[b[i]] < 0 )
                       {
                              flag = -1;
                              break;    
                       }
            }
            if( im[a] > 0 )
            {
                 for( int i = 0; i < num;   i++ )
                 {
                       im[b[i]] = -1;
                       g[a][b[i]] = 1;    
                 }    
            }
            else if( im[a] < 0 )
            {
                 for( int i = 0; i < num;   i++ )
                 {
                       im[b[i]] = 1;
                       g[b[i]][a] = 1;    
                 }                      
            }
            else if( flag > 0 )
            {
                 im[a] = -1;
                 for( int i = 0; i < num; i++ )
                 {
                          im[b[i]] = 1;
                          g[b[i]][a] = 1;       
                 } 
            } 
            else if( flag < 0 )
            {
                 im[a] = 1;
                 for( int i = 0; i < num; i++ )
                 {
                        im[b[i]] = -1;
                        g[a][b[i]] = 1;      
                 }  
            } 
            else if( im[a] == 0 && flag == 0 )
            {
                 im[a] = 1;
                 for( int i = 0; i < num; i++ )
                 {
                       im[b[i]] = -1;
                       g[a][b[i]] = 1;      
                 }
            }
            
                
        }    //for
        

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