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

怎么就过不了呢??? 1988

Posted by lidepeng123 at 2012-08-09 10:44:01 on Problem 1988
#include <iostream>
#include<string.h>
#include <stdio.h>
using namespace std;
int p[30010];
int up[30010];
int sum[30010];
int find (int x)
{   if(p[x] == x)
         {return  x;}
    else
       {p[x]=find(p[x]);
          return p[x] ;
       }
}

void unsin_123(int x ,int y)
{   int px,py;
    px=find(x);
    py=find(y);
    if(px!=py)
    {
        up[py]+=sum[px];
        sum[px]+=sum[py];
         p[py]=px;
    }
}

int main()
{   int n;
    char str;
    int j,k;
       memset(up,0,sizeof(up));
       //cin>>n;
       scanf("%d",&n);
          for(int i=1;i<=n;i++ )
           p[i]=i;

       for(int i=1;i<=n;i++)
       sum[i]=1;
       while (n>0)
       {   cin>>str;
           if(str=='M')
             {//cin>>j>>k;
                 scanf("%d%d",&j,&k);
             unsin_123(j,k);
             }
             else if(str=='C')
             {//cin>>j;
                 scanf("%d",&j);
              //cout<<sum[p[j]]-1-up[j]<<endl;
              printf("%d",sum[p[j]]-1-up[j]);
             }
          n--;
       }

    return 0;
}

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