hdoj 2120 Ice_cream's world I【求成环数】
Ice_cream's world I
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 741 Accepted Submission(s):
429
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.
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.
awarded.
One answer one line.
0 1
1 2
1 3
2 4
3 4
0 5
5 6
6 7
3 6
4 7
#include<stdio.h>
#include<string.h>
#define MAX 1010
int set[MAX];
int sum=0;
int find(int fa)
{
int t;
int ch=fa;
while(fa!=set[fa])
fa=set[fa];
while(ch!=fa)
{
t=set[ch];
set[ch]=fa;
ch=t;
}
return fa;
}
void mix(int x,int y)
{
int fx,fy;
fx=find(x);
fy=find(y);
if(fx!=fy)
set[fx]=fy;
else
sum++;
}
int main()
{
int n,m,i,a,b;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<=n;i++)
set[i]=i;
for(i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
mix(a,b);
}
printf("%d\n",sum);
sum=0;
}
return 0;
}
hdoj 2120 Ice_cream's world I【求成环数】的更多相关文章
- HDOJ 2120 Ice_cream's world I
Ice_cream's world I ice_cream's world is a rich country, it has many fertile lands. Today, the queen ...
- hdoj 2121 Ice_cream’s world II 【没有最低树的根节点】
称号:pid=2121" target="_blank">hdoj 2121 Ice_cream's world II 题意:题目是一道躶题,给n个点,m条边的有向 ...
- hdu 2120 Ice_cream's world I
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2120 Ice_cream's world I Description ice_cream's worl ...
- 帮初学者改代码——playerc之“练习:求完数问题”(下)
前文链接:帮初学者改代码——playerc之“练习:求完数问题”(上) 再来看看be_ferfect()应该如何改. be_ferfect()函数的功能是判断number是否为完数,同时把因子对写入d ...
- 帮初学者改代码——playerc之“练习:求完数问题”(上)
原文:“练习:求完数问题” 原代码: // #include <stdio.h> #include <stdlib.h> #include <math.h> #de ...
- openmp 并行求完数
// GetWanShu.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "omp.h" #inclu ...
- d008: 求两数的整数商 和 商
内容: 求两数的整数商 和 商 ,商保留两位小数 输入说明: 一行 两个整数 输出说明: 一行,一个整数,一个实数(两位小数) 输入样例: 12 8 输出样例 : 1 1.50 #include ...
- d007: 求两数的整数商 和 余数
内容: 求两数的整数商 和 余数 输入说明: 一行两个整数 输出说明: 一行两个整数 输入样例: 18 4 输出样例 : 4 2 #include <stdio.h> int main ...
- ZOJ3574(归并排序求逆数对)
Under Attack II Time Limit: 5 Seconds Memory Limit: 65536 KB Because of the sucessfully calcula ...
随机推荐
- nginx面试题
1.Nginx是如何实现高并发的 service nginx start之后,然后输入#ps -ef|grep nginx,会发现Nginx有一个master进程和若干个worker进程,这些work ...
- [Unity菜鸟] Unity发布web后,从HTML调用本地文件
1. 遇到的问题 从xml读数据,xml的编码用中文就会乱码,改编码格式就调用不了.目前采用默认的ANSI编码. .exe .txt .xlsx .xml .test Run √ ...
- MySQL复制应用中继日志解析
前言:SQL线程应用中继日志,在binlog_format是row格式的时候,是居于主键更新,下面结合一张图来证明 1.从一个大神那边得到一张图片,SQL线程应用中继日志流程,下面就实验验证一下:(P ...
- Oracle数据导入导出imp/exp sp2-0734:未知的命令开头'imp...解决方法
Oracle数据导入导出imp/exp sp2-0734:未知的命令开头'imp...解决方法 sp2-0734:未知的命令开头'imp 忽略了剩余行默认分类 www.2cto.com 应该 ...
- 基于邻接矩阵的广度优先搜索遍历(BFS)
题目:http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2141&cid=1186 #include<stdio.h> #incl ...
- HNOI2008 GT 考试
我不明白为什么是DP,我感觉和vijos的核电站问题(https://www.vijos.org/p/1232)差不多啊 这是别人的题解:http://www.cnblogs.com/Skywalke ...
- Java集群优化——dubbo+zookeeper构建高可用分布式集群
不久前,我们讨论过Nginx+tomcat组成的集群,这已经是非常灵活的集群技术,但是当我们的系统遇到更大的瓶颈,全部应用的单点服务器已经不能满足我们的需求,这时,我们要考虑另外一种,我们熟悉的内容, ...
- Linux sysfs device_attribute
/*************************************************************************** * Linux sysfs device_at ...
- acdream LCM Challenge (最小公倍数)
LCM Challenge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Su ...
- ORACLE参数文件
一.oracle pfile/spfile区别 pfile 默认的名称为“init+例程名.ora”文件路径:E:\oracle\product\10.2.0\db_1\dbs,这是一个文本文件 ...