第一次见到UKE

P3367 【模板】并查集

Veraku @ 2017-11-09 19:10:18

代码:

#include <cstdio>
#include <iostream>
using namespace std;
const int MAXN = 10005;
int p[MAXN], n, m;
inline int find(int &x)
{
    return p[x] == x ? x : p[x] = find(p[x]);
}
void merge(int &x, int &y)
{
    p[x] = y;
}
int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 0; i <= n; ++i)
        p[i] = i;
    for(int i = 0; i < m; ++i)
    {
        static int z, x, y;
        scanf("%d%d%d", &z, &x, &y);
        if(z == 1)
            merge(x, y);
        else
        {
            if(find(x) == find(y))
                printf("Y\n");
            else
                printf("N\n");
        }
    }
    return 0;
} 

by Hades18 @ 2017-11-09 19:36:28

想必是评测机炸了


by 蹲在丛中笑 @ 2017-11-09 19:48:36

yyk is so strong


by Veraku @ 2017-11-09 20:12:39

。。。


|