题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1856

题意:朋友圈问题,A和B是朋友,B和C是朋友则A和C也是朋友,依次类推,题目的意思就是求最大的朋友圈,即求最大集合中元素的个数。裸的并查集加个秩数组就行了。

#include <stdio.h>

int father[];
int rank[]; int Find_Set (int x)
{
if(x!=father[x])
father[x] = Find_Set(father[x]);
return father[x];
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<;i++)
{
father[i] = i;
rank[i] = ;
} for(int i=;i<n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
int fx = Find_Set(x);
int fy = Find_Set(y);
if(fx!=fy)
{
father[fy] = fx;
rank[fx] += rank[fy];
}
} int _max = ;
for(int i=;i<;i++)
_max = (rank[i]>_max) ? rank[i]:_max;
printf("%d\n",_max);
}
return ;
}

HDU(1856),裸的带权并查集的更多相关文章

  1. hdu 5441 Travel 离线带权并查集

    Travel Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5441 De ...

  2. Hdu 2047 Zjnu Stadium(带权并查集)

    Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. How Many Answers Are Wrong (HDU - 3038)(带权并查集)

    题目链接 并查集是用来对集合合并查询的一种数据结构,或者判断是不是一个集合,本题是给你一系列区间和,判断给出的区间中有几个是不合法的. 思考: 1.如何建立区间之间的联系 2.如何发现悖论 首先是如何 ...

  4. hdu 5441 travel 离线+带权并查集

    Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Others) Problem Descript ...

  5. hdu 2818 Building Block (带权并查集,很优美的题目)

    Problem Description John are playing with blocks. There are N blocks ( <= N <= ) numbered ...N ...

  6. hdu 3635 Dragon Balls (带权并查集)

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  7. How Many Answers Are Wrong HDU - 3038 (经典带权并查集)

    题目大意:有一个区间,长度为n,然后跟着m个子区间,每个字区间的格式为x,y,z表示[x,y]的和为z.如果当前区间和与前面的区间和发生冲突,当前区间和会被判错,问:有多少个区间和会被判错. 题解:x ...

  8. hdu 3047–Zjnu Stadium(带权并查集)

    题目大意: 有n个人坐在zjnu体育馆里面,然后给出m个他们之间的距离, A B X, 代表B的座位比A多X. 然后求出这m个关系之间有多少个错误,所谓错误就是当前这个关系与之前的有冲突. 分析: 首 ...

  9. HDU 3047 Zjnu Stadium(带权并查集)

    题意:有一个环形体育场,有n个人坐,给出m个位置关系,A B x表示B所在的列在A的顺时针方向的第x个,在哪一行无所谓,因为假设行有无穷个. 给出的座位安排中可能有与前面矛盾的,求有矛盾冲突的个数. ...

随机推荐

  1. 使用MJExtension中要注意的地方

    MJExtension git地址  https://github.com/CoderMJLee/MJExtension#JSON_Model Model contains model-array[模 ...

  2. Lintcode: Segment Tree Build

    The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...

  3. 转:python webdriver API 之alert/confirm/prompt 处理

    webdriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到 alert/conf ...

  4. linux [Fedora] 下的 "飞秋/飞鸽传书"

    官方网址: http://www.msec.it/blog/?page_id=11 http://software.opensuse.org/download.html?project=home:co ...

  5. Linux内核之旅 链表实现

    #include "stdio.h" #include "stdlib.h" struct list_head{ struct list_head *prev; ...

  6. Java实现数组按数值大小排序

    package shb.java.test; /** * 比较数组中元素的大小,按从大到小顺序排列. * @Package:shb.java.test * @Description: * @autho ...

  7. angular ng-href

    farmApp.config([ '$compileProvider', function( $compileProvider ) { $compileProvider.aHrefSanitizati ...

  8. highcharts 实例

    <script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript">< ...

  9. ahb2apb和apb2apb async bridge

    AHB 3.0目前不支持security world. AHB到APB的async bridge主要包括三个部分: 1)AHB domain 1)产生信号hactive = HSEL & HT ...

  10. NOIP200407合唱队形+最长上升子序列O(n^2)详解

    合唱队形解题报告 2016-05-12   4:30——6:45 NOIP200407合唱队形 难度级别:A: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:20000 ...