HDU 1856

简介: More is better Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others) Total Submission(s): 6073    Accepted Submission(s): 2225 Problem Description Mr Wang w

More is better

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 6073    Accepted Submission(s): 2225


Problem Description
Mr Wang wants some boys to help him with a project. Because the project is rather complex,  the more boys come, the better it will be. Of course there are certain requirements.

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.
 

Input
The first line of the input contains an integer n (0 ≤ n ≤ 100 000) - the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)
 

Output
The output in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep. 
 

Sample Input
 
 
4 1 2 3 4 5 6 1 6 4 1 2 3 4 5 6 7 8
 

Sample Output
 
 
4 2
Hint
A and B are friends(direct or indirect), B and C are friends(direct or indirect), then A and C are also friends(indirect). In the first sample {1,2,5,6} is the result. In the second sample {1,2},{3,4},{5,6},{7,8} are four kinds of answers.
 

Author
lxlcrystal@TJU
 

Source
 
 #include"stdio.h"
int p[10000010], num[10000010]={0};

int find(int x)
{
    int k, j, r;
          r = x;
    while(r != p[r])
        r = p[r];
    k = x;
    while(k != r)            //注意这里的路径压缩
    {
        j = p[k];
        p[k] = r;
        k = j;
    }
    return r;
}

long count ()
{
    long i, max = 0 ;
    for (i = 1 ; i <= 10000000 ; i++) num[i] = 0 ;
    for (i = 1 ; i <= 10000000 ; i++) num[find(i)]++ ;              //用数组存放
    for (i = 1 ; i <= 10000000 ; i++) if (num[i] > max) max = num[i] ;
    return max ;
}
int main()
{
    long n, p1, p2, i, max = 0, j, cnt;
    while(scanf("%d", &n) != EOF)
    {
        for(i = 1; i <= 10000000; i++)
            p[i] = i;
        i = 1;
        while(i <= n)
        {
            scanf("%ld%ld", &p1, &p2);
            if(find(p1) != find(p2))
            {
                 p[find(p2)]=find(p1);
            }
            i++;
        }

        printf("%ld\n", count());
    }
    return 0;
}


目录
相关文章
|
存储
CocosCreator3.8研究笔记(十一)CocosCreator Prefab(预制件)理解
CocosCreator3.8研究笔记(十一)CocosCreator Prefab(预制件)理解
1746 0
|
3月前
|
存储 自然语言处理 中间件
《AgentScope 2.0实战指南》09 - RAG 检索增强生成
《AgentScope 2.0实战指南》第9章详解RAG服务化:将私有文档(PDF/Word/Markdown等)经解析、切块、向量化后构建可检索知识库,通过RAGMiddleware无缝接入Agent,实现“所问即所得、答案可溯源”的生产级增强问答。代码开箱即用,支持多租户与动态更新。(239字)
539 0
|
9月前
|
存储 安全 编译器
C语言深度解析:变长数组(VLA)的底层逻辑与避坑指南
变长数组(VLA)是C99引入的栈上动态数组,长度运行时确定,访问快但无安全检查。易致栈溢出、野指针、跨平台兼容问题,仅适用于小尺寸、短生命周期场景,大数组务必用malloc。
1016 38
|
7月前
|
人工智能 监控 调度
2026 企业 Agent 落地爆发:90% 企业卡在第一步
2026年AI Agent企业落地进入关键期,但90%企业卡在第一步:缺的不是大模型,而是支撑Agent稳定运行的企业级底座。JBoltAI聚焦工程化落地,提供统一模型网关、可信数据层、标准化开发与可观测运营能力,助力AI从演示走向真实业务。(239字)
|
7月前
|
人工智能 自然语言处理 机器人
[开源框架-实战]用 Hermes Agent 搭一个微信播报机器人
30 分钟,零 Python 代码,搭出一个每天早上 9 点把 GitHub Trending 推送到你微信的机器人。顺带把 Hermes 的 Skill、Gateway、Cron 四个招牌能力全用上。
1672 8
|
12月前
|
算法 物联网 机器人
蓝牙信标、UWB等主流室内定位无线技术的参数对比、核心算法和选型指南详解(二)
本文系统解析室内定位无线技术,涵盖蓝牙、Wi-Fi、UWB、RFID、超声波、可见光等主流技术的原理、参数对比与核心算法(RSSI、TDOA、AoA),并提供按精度、成本、场景匹配的选型指南,助力民用、工业、资产盘点及特殊环境下的最优技术选择。如果您想进一步了解定位的案例,欢迎关注、评论留言~也可搜索lbs智能定位。
|
11月前
|
存储 人工智能
什么是QR二维码 ?
QR码是由Denso Wave于1994年发明的二维条码,具高容量、强纠错、易识别等特点,广泛应用于移动支付、票务、物流、数字护照等领域。其结构包含定位、对齐、时序图案及数据区,支持数字、字母、字节、汉字等编码模式,结合智能手机发展,已成为数字化生活的重要工具。
3600 6
|
人工智能 自动驾驶 物联网
5G到底有多牛?一文看懂它的原理与优势!
5G到底有多牛?一文看懂它的原理与优势!
1195 19
|
机器学习/深度学习 缓存 编解码
AIGC 商业化道路探索 - Stable Diffusion 商业化应用(上)
Stable Diffusion 应用到商业领域的案例越来越多,商用场景下的技术架构应当如何构建?本文基于阿里云近期的一个 Stable Diffusion 商业案例,对大规模底模切换、大量 LoRA 调优的场景提出一个商业场景适用的技术架构,并已实现部署交付,稳定运行。
|
人工智能 算法 语音技术
Video-T1:视频生成实时手术刀!清华腾讯「帧树算法」终结闪烁抖动
清华大学与腾讯联合推出的Video-T1技术,通过测试时扩展(TTS)和Tree-of-Frames方法,显著提升视频生成的连贯性与文本匹配度,为影视制作、游戏开发等领域带来突破性解决方案。
701 4
Video-T1:视频生成实时手术刀!清华腾讯「帧树算法」终结闪烁抖动