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

有木有大神帮忙看看,死活wa;

Posted by AK47biubiubiu at 2016-07-04 11:12:29 on Problem 1988
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=30000+10;
struct node
{
    int h,low;
} a[N];
int f[N],m;
int find(int x)
{
    if(f[x]==-1)
        return x;
    a[x].low+=a[f[x]].low;
    return f[x]=find(f[x]);
}
int main()
{
    scanf("%d",&m);
    char c;
    int x,y;
    memset(f,-1,sizeof(f));
    for(int i=1; i<=N; i++)
        a[i].h=1,a[i].low=0;
    while(m--)
    {
        getchar();
        scanf("%c",&c);
        if(c=='C')
        {
            scanf("%d",&x);
           find(x);
           printf("%d\n",a[x].low);
        }
        else
        {
            scanf("%d%d",&x,&y);
            int xx=find(x);
            int yy=find(y);
            if(xx==yy)
                continue;
            f[xx]=yy;
            a[xx].low=a[yy].h;
            a[yy].h+=a[xx].h;
        }
    }
    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