蒟蒻0分求助%%%

P3367 【模板】并查集

EmiliaQAQ @ 2018-11-06 20:51:49

为什么全是RE呀...

#include<iostream>
#include<cstdio>
using namespace std;
int n,m,z,x,y,f[10001];
int find(int p)
{
    if(p==f[p])return p;
    else f[p]=find(f[p]);
}
int main()
{
    cin>>n>>m;
    int i;
    for(i=1;i<=n;i++)
    {
        f[i]=i;
    }
    for(i=1;i<=m;i++)
    {
        cin>>z>>x>>y;
        if(z==1)
        {
            f[find(x)]=find(y);
        }
        if(z==2)
        {
            if(find(x)==find(y))
                cout<<"Y"<<endl;
            else
                cout<<"N"<<endl;
        }
    }
    return 0;
}

by 已注销%Jm9VScx @ 2018-11-06 20:53:57

你说呢你没有女装


by Lousiaaa @ 2018-11-06 20:56:35

find函数里 else return f[p]=find(f[p]) 加个return应该就好了吧


by EmiliaQAQ @ 2018-11-06 20:57:12

@L_TF >_>


by Malthael_ @ 2018-11-06 20:58:59

@EmiliaQAQ 快女装 快女装!然后AKnoip


by EmiliaQAQ @ 2018-11-06 20:59:06

@LYQ 哦。。谢谢


by wuzhaoxin @ 2018-11-06 20:59:36

@EmiliaQAQ 你开O2可能就过了


by 绅士狗 @ 2018-11-06 20:59:58

你要AK NOIP


by EmiliaQAQ @ 2018-11-06 21:00:22

@禅师的同学 mmp


by 绅士狗 @ 2018-11-06 21:00:50

骂人,管理员快来把他封禁了


by cxccxc @ 2018-11-06 21:01:21

int find(int p)
{
    if(p==f[p])return p;
    else return f[p]=find(f[p]);
}

你只写了一个return!


| 下一页