zoukankan      html  css  js  c++  java
  • HDU

    //本题用cin超时啊,要用scanf
    #define  _CRT_SECURE_NO_WARNINGS
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <algorithm>
    using namespace std;
    
    const int maxn = 10000001;
    int pre[maxn];
    int topcnt[maxn];
    
    int Find(int x)
    {
        int l = x;
        while (l != pre[l])
            l = pre[l];
        while (l != pre[x]){
            int t = pre[x];
            pre[x] = l;
            x = t;
        }
        return l;
    }
    
    void join(const int x, const int y)
    {
        int fx = Find(x);
        int fy = Find(y);
        pre[fx] = fy;
    }
    
    int main()
    {
        int n; 
        while (~scanf("%d", &n)){
            if (n == 0){
                printf("1
    ");
                continue;
            }
            for (int i = 0; i < maxn; i++)
                pre[i] = i;
            memset(topcnt, 0, sizeof(topcnt));
            while (n--){
                int x, y; scanf("%d %d", &x, &y);
                join(x, y);
            }
            for (int i = 1; i < maxn; i++)
                topcnt[Find(i)]++;
            printf("%d
    ", *max_element(topcnt + 1, topcnt + maxn));
        }
        return 0;
    }

  • 相关阅读:
    MGR
    复制参数优化
    mysql复制
    sysbench
    mysql 用户及权限
    MySQL多实例安装
    PHP常用数组函数
    AJAX传递数据的两种编码x-www-form-urlencoded与json的区别
    使用PHP操作文件
    var_dump和var_export区别
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312742.html
Copyright © 2011-2022 走看看