HDU-2120-Ice_cream's world I

简介: HDU-2120-Ice_cream's world I


Ice_cream’s world I

Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)

Total Submission(s) : 59 Accepted Submission(s) : 39

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

ice_cream’s world is a rich country, it has many fertile lands. Today, the queen of ice_cream wants award land to diligent ACMers. So there are some watchtowers are set up, and wall between watchtowers be build, in order to partition the ice_cream’s world. But how many ACMers at most can be awarded by the queen is a big problem. One wall-surrounded land must be given to only one ACMer and no walls are crossed, if you can help the queen solve this problem, you will be get a land.

Input

In the case, first two integers N, M (N<=1000, M<=10000) is represent the number of watchtower and the number of wall. The watchtower numbered from 0 to N-1. Next following M lines, every line contain two integers A, B mean between A and B has a wall(A and B are distinct). Terminate by end of file.

Output

Output the maximum number of ACMers who will be awarded.

One answer one line.

Sample Input

8 10

0 1

1 2

1 3

2 4

3 4

0 5

5 6

6 7

3 6

4 7

Sample Output

3

题目意思:

有8个塔 有10条线(10 组数据 每组数据有两个数,意思是这两个塔之间有墙连着 也就是有十条线),解决的问题就是这十条线把这个封闭的区域分成了几小块。每条线之间还有可能相接,那么你所要做的就是这十条线能构成几个环,就是所形成的区域数

#include<cstdio>
#include<cstring>
#define maxn 1000+10
int p[maxn],ans=0;
int find(int x)
{
    while(x!=p[x])
        x=p[x];
    return p[x];
}
int he(int a,int b)
{
    if(find(a)!=find(b))
       p[find(a)]=find(b);
    else
        ans++;  // 如果根节点相同那么就成环了,++
    return  ans;
}
int main()
{
            int i,x,y;
            while(~scanf("%d%d",&x,&y))
            {
                for(i=0;i<x;i++)
                   p[i]=i;
                int x1,y1;
                while(y--)
               {
                    scanf("%d%d",&x1,&y1);
                    he(x1,y1);
               }
               printf("%d\n",ans);
               ans=0;
            }
    return 0;
}


目录
相关文章
|
监控 物联网 应用服务中间件
流媒体方案之Nginx——实现物联网视频监控项目
流媒体方案之Nginx——实现物联网视频监控项目
流媒体方案之Nginx——实现物联网视频监控项目
|
存储 人工智能 自动驾驶
FMW 2023 | 阿里云存储邀您一同探讨“芯存储 AI未来”
8月29-30日,以“芯存储 AI未来”为主题的2023全球闪存峰会(FMW)在杭州开元名都大酒店举办。
596 0
|
计算机视觉
OpenCV滑动条(createTrackbar()函数)如何在多个维度进行同步调整?
这篇文章介绍了如何在OpenCV中使用`createTrackbar()`函数创建多个滑动条以同步调整图像的多个维度(如亮度和对比度),通过将不同滑动条的回调函数合并为一个,确保它们在同一图像基础上进行调整。
|
运维 监控 数据可视化
贝锐蒲公英视频监控方案用户答疑:4G/5G入网,没有公网IP也能用
贝锐蒲公英提供创新的视频监控解决方案,适用于多种监控场景,无需依赖专网或公网IP,支持4G/5G网络,实现快速部署与高质量传输。其云端配置平台简化操作流程,具备二层组网与弱网优化功能,确保视频传输流畅。蒲公英还支持多品牌设备集中管理,提供专业级技术支持,适用于有无公网IP环境,确保远程监控高效稳定。
279 4
|
12月前
|
存储 监控 安全
阿里云携手庆视互联数据迁云,助力全球业务升级
智能家居数据迁云,守护千万家庭安全
|
编解码 监控 Ubuntu
MJPG-streamer方案实现物联网视频监控
MJPG-streamer方案实现物联网视频监控
MJPG-streamer方案实现物联网视频监控
|
人工智能 编解码 程序员
AI绘画普及课【二】图生图
AI绘画普及课【二】图生图
504 0
|
数据采集 JSON 监控
Zabbix物联网可视化开发文档
Zabbix物联网可视化开发文档
264 1
|
机器学习/深度学习 人工智能 算法
开源中文医疗大模型华佗GPT来了,真人医生盲测效果优于ChatGPT
开源中文医疗大模型华佗GPT来了,真人医生盲测效果优于ChatGPT
1089 0