More is better(并差集)
More is better
Time Limit : 5000/1000ms (Java/Other) Memory Limit : 327680/102400K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way.
#include<stdio.h>
int relate[],num[];//num[]记录个数;
int min;
int find(int x){
int r=x;
while(r!=relate[r])r=relate[r];
int i=x,j;
while(i!=r)j=relate[i],relate[i]=r,i=j;
return r;
}
void initial(){
for(int i=;i<=;++i)relate[i]=i,num[i]=;
}
void merge(int x,int y){
int f1,f2;
f1=find(x);f2=find(y);
if(f1!=f2)relate[f1]=f2,num[f2]+=num[f1];
min=min>num[f2]?min:num[f2];
}
int main(){
int n,temp1,temp2;
while(~scanf("%d",&n)){
min=;initial();
while(n--){
scanf("%d%d",&temp1,&temp2);
merge(temp1,temp2);
}
printf("%d\n",min);
}
return ;
}
More is better(并差集)的更多相关文章
- C# 数组的交集、差集、并集
C# 数组的交集.差集.并集 工作中经常会用这方面的知识来检查那些字段是必须输入的,那些是禁止输入. using System; using System.Collections.Generic; u ...
- java求字符串数组交集、并集和差集
import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Ma ...
- SQL中对于两个不同的表中的属性取差集except运算
SQL中对两个集合取差集运算,使用except关键字,语法格式如下: SELECT column_name(s) FROM table_name1 EXCEPT SELECT column_name( ...
- C# Linq 交集、并集、差集、去重
using System.Linq; List<string> ListA = new List<string>(); List<string> L ...
- js取两个数组的交集|差集|并集|补集|去重示例代码
http://www.jb51.net/article/40385.htm 代码如下: /** * each是一个集合迭代函数,它接受一个函数作为参数和一组可选的参数 * 这个迭代函数依次将集合的每一 ...
- Linux 对比两个文本的交集和差集(comm)
200 ? "200px" : this.width)!important;} --> 介绍 comm命令可以对两个已排序好的文本的内容进行交集和差集的对比,记住必须是已排序 ...
- [转]SQL 操作结果集 -并集、差集、交集、结果集排序
本文转自:http://www.cnblogs.com/kissdodog/archive/2013/06/24/3152743.html 操作结果集 为了配合测试,特地建了两个表,并且添加了一些测试 ...
- scala中集合的交集、并集、差集
scala中有一些api设计的很人性化,集合的这几个操作是个代表: 交集: scala> Set(1,2,3) & Set(2,4) // &方法等同于interset方法 sc ...
- Codeforces Round#250 D. The Child and Zoo(并差集)
题目链接:http://codeforces.com/problemset/problem/437/D 思路:并差集应用,先对所有的边从大到小排序,然后枚举边的时候,如果某条边的两个顶点不在同一个集合 ...
- java list 交集 并集 差集 去重复并集
package com; import java.util.ArrayList;import java.util.Iterator;import java.util.List; public clas ...
随机推荐
- UGUI Button和Toogle动态添加事件
如果你想动态创建Button和Toogle 等等一系列控件,需要动态添加事件的如下. 拿button和Toogle抛砖引玉O(∩_∩)O~ using UnityEngine; using Syste ...
- KVO奥秘
序言 在iOS开发中,苹果提供了许多机制给我们进行回调.KVO(key-value-observing)是一种十分有趣的回调机制,在某个对象注册监听者后,在被监听的对象发生改变时,对象会发送一个通知给 ...
- Android应用程序注册广播接收器(registerReceiver)的过程分析
前 面我们介绍了Android系统的广播机制,从本质来说,它是一种消息订阅/发布机制,因此,使用这种消息驱动模型的第一步便是订阅消息:而对 Android应用程序来说,订阅消息其实就是注册广播接收器, ...
- Timer.4 - Using a member function as a handler
In this tutorial we will see how to use a class member function as a callback handler. The program s ...
- html_day2
总结下今天学的HTML知识.单词 跑马灯标记 <marquee></marquee>属性: direction:滚动的方向 取值:left .right. up. down b ...
- BFC,IFC,GFC,FFC的定义及功能
What's FC?一定不是KFC,FC的全称是:Formatting Contexts,是W3C CSS2.1规范中的一个概念.它是页面中的一块渲染区域,并且有一套渲染规则,它决定了其子元素将如何定 ...
- SQL Server 模式和名称解析
模式实际上是名称空间,因此在SQL Serve中调用数据库对象时,一定要设置对象引用的环境.每个用户都被赋予了一个默认模式,在用户登录SQL Server并凋用数据库对象时,这个默认模式就是对象引用方 ...
- 在 Xcode中 修改文件中自动创建的Created by和Copyright
在Xcode里创建的时候,会自动生成注释 // Created byxxx on 15/7/10. // Copyright (c) 2015年 xxxx. All rights reserved ...
- UIView的动画之初步学习
animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options:<#(UIView ...
- (转)eclipse 代码自动补全
转自:http://blog.csdn.net/yushuwai2010/article/details/11856129 一般默认情况下,Eclipse的代码提示功能是比MicrosoftVisua ...