zoukankan      html  css  js  c++  java
  • hdoj1856

    More is better


    /***************************************************************\
    *Author: 小呼
    *Created Time: Mon 12 Jul 2010 09:21:56 AM CST
    *File Name: a.cpp
    *Description://并查集,增加信心的题目
    \***************************************************************/

    //*========================*Head File*========================*\\

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    /*----------------------*Global Variable*----------------------*/
    int
    frd[
    10000001];
    int
    A,B,n;

    //*=======================*Main Program*=======================*//
    using namespace std;

    int
    find(int x){
    if
    (frd[x]>
    0)
    frd[x]=find(frd[x]);
    return
    frd[x]>
    0?frd[x]:x;
    }

    void
    union_set(int x,int y){
    x=find(x);y=find(y);
    if
    (find(x)<find(y)){
    frd[x]+=frd[y];
    frd[y]=x;
    }

    else
    {
    frd[y]+=frd[x];
    frd[x]=y;
    }
    }


    int
    main(){

    //freopen("input","r",stdin);
    while(scanf("%d",&n)!=EOF){
    int
    res=-
    1;
    memset(frd,-
    1,sizeof(frd));
    for
    (int i=
    1;i<=n;++i){
    scanf(
    "%d%d",&A,&B);
    A=find(A);
    B=find(B);
    if
    (A!=B){
    int
    temp=frd[A]+frd[B];
    res=res<temp?res:temp;
    union_set(A,B);
    }
    }

    printf(
    "%d\n",-1*res);
    }

    return
    0;
    }
  • 相关阅读:
    Java Object类及其常用方法
    Java 抽象类和抽象方法
    Java 多态
    Java 继承
    Java Scanner类
    正则表达_1
    「暑期集训day14」掠影
    「暑期集训day13」苦闷
    「暑期集训day12」苦楚
    「暑期集训day11」旧殤
  • 原文地址:https://www.cnblogs.com/Open_Source/p/1904932.html
Copyright © 2011-2022 走看看