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
欢迎参加IJCAI 2020麻将智能体竞赛,大奖等你拿!Welcome to IJCAI 2020 Mahjong AI competition with amazing prizes!

为啥讲findr()放到主函数里还是tle

Posted by Tiger_Dz at 2019-10-07 20:47:48 on Problem 1611
#include <cstdio>

using namespace std;

int N,M;//学生数量为N-1个,包括0;
int data[30000];
int unit(int i,int j)
{
    for (; data[j] >= 0; j = data[j])
        ;
    if(data[i]< data[j])
    {
        data[i] += data[j];
        data[j]  = i;
        return i;
    }
    else
    {
        data[j] += data[i];
        data[i] =  j;
        return j;
    }
}
int main()
{
    while (scanf("%d %d",&N,&M),N)
    {
        for(int i =0;i<N;i++)
            data[i] = -1;
        for (int  i = 0,j; i < M; i++) // 每组数据有两种情况 ,这一组单独成树或包含其他的树
        {
                scanf("%d",&j);
            for (int k=0,s,t1=0,t2; k <j ; k++)
                {
                    scanf("%d",&s); //输入 
                    if(k == 0){
                        for (; data[s] >= 0; s = data[i])
                            ;
                            t1 =s;
                    } //第一颗树的根作为初始根
                    else
                    {
                        t1 = unit(t1,s);
                    }
                }
        }
        int i = 0;
        for (; data[i] >= 0; i = data[i])
            ;
        printf("%d\n",-(data[i]));
    }
    
}

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