本地测试是对的,交上去为什么全WA啊

P3367 【模板】并查集

David207 @ 2020-08-08 09:50:15

代码如下

#include<bits/stdc++.h>
using namespace std;
int f[100000000];
int x,y;
int n,m,p;
int d[1000000];
inline int read() {
    char ch = getchar(); 
    int x = 0, f = 1;
    while(ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    } while('0' <= ch && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    } return x * f;
}
int found(int x)
{
    if(f[x]==x) return f[x];
    f[x]=found(f[x]);
    return f[x];
}
int ad(int x,int y)
{
    int xx=found(x);
    int yy=found(y);
    f[yy]=xx;
}
char c;
int main()
{
    n=read();
    m=read();
    for(int i=1;i<=n;i++)
    {
        f[i]=i;
    }
    for(int i=1;i<=m;i++)
    {
        c=getchar();
        if(c=='1')
        {
            x=read();
            y=read();
            ad(x,y);
        }
        if(c=='2')
        {
            x=read();
            y=read();
            if(found(x)==found(y))
            {
                puts("Y");
            }
            else
            {
                puts("N");
            }
        }
    }
    return 0;
}

by Steven__Chen @ 2020-08-08 09:51:54

妈耶,这f数组什么情况


by Smile_Cindy @ 2020-08-08 09:55:05

here


by David207 @ 2020-08-08 10:03:21

@Steven__Chen f数组开小一点也还是不行啊


|