Ice_cream's world I--hdu2120
Ice_cream's world I
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 839 Accepted Submission(s):
488
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.
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 10010
using namespace std; int per[maxn],sum;
void init()
{
int i;
for(i=;i<maxn;i++)
{
per[i]=i;//初始化数组
}
}
int find(int x)//查找根节点
{
int t=x;
while(t!=per[t])
t=per[t];
return t;
}
void join(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx==fy)
sum++;//环的个数
else
per[fx]=fy;
}
int main()
{
int a,b,i,m,n;
while(scanf("%d%d",&a,&b)!=EOF)
{
init();
sum=;
for(i=;i<b;i++)
{
scanf("%d%d",&m,&n);
join(m,n);
}
printf("%d\n",sum);
}
return ;
}
Ice_cream's world I--hdu2120的更多相关文章
- 【HDU2120】Ice_cream's world I(并查集基础题)
查环操作,裸题.一次AC. #include <iostream> #include <cstring> #include <cstdlib> #include & ...
- A - Ice_cream’s world III
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- 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 ...
- HDU 2121 Ice_cream’s world II 不定根最小树形图
题目链接: 题目 Ice_cream's world II Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 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/Othe ...
- hdoj 2122 Ice_cream’s world III
并查集+最小生成树 Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- Ice_cream’s world III--2122
Ice_cream’s world III Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Ice_cream's world I
Ice_cream's world I Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
- Ice_cream’s world III(prime)
Ice_cream’s world III Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
随机推荐
- [C++程序设计]用指针变量作函数参数接收数组地址
#include <iostream> using namespace std; void select_sort(int *p, int n) { int i, j, k; ; i &l ...
- LaTeX使用titlesec宏包改变章节编号形式的方法
1.titleformat宏包命令详解 LaTeX中可以用titlesec宏包中的titleformat命令来改变标题形式: 导入宏包: \usepackage{titlesec} 改变标题的代码如下 ...
- python安装第三方包的两种方式
最近研究QQ空间.微博的(爬虫)模拟登录,发现都涉及RSA算法.于是需要下一个RSA包(第三方包).折腾了很久,主要是感觉网上很多文章对具体要在哪里操作写得不清楚.这里做个总结,以免自己哪天又忘了. ...
- New Start!
博客连续搬了几个地方,从一开始的网易lofter,到点点,再到后来新浪sae自己搭建,折腾了很久,都因为各种原因没有坚持写博. 想了想,其实说到底还是因为懒,根本原因是自己没有毅力.什么不能贴代码,不 ...
- python解释器内建函数002
001.dict 函数来创建字典 #!/usr/bin/python #!coding:utf-8 if __name__ == "__main__": dct001=dict(h ...
- [TYVJ] P1055 沙子合并
沙子合并 描述 Description 设有N堆沙子排成一排,其编号为1,2,3,…,N(N<=300).每堆沙子有一定的数量,可以用一个整数来描述,现在要将这N堆沙子合并成为一堆,每次 ...
- 编程修养-C语言篇(二)
1.版权和版本——————— 好的程序员会给自己的每个函数,每个文件,都注上版权和版本. 对于C/C++的文件,文件头应该有类似这样的注释: /*************************** ...
- BZOJ NOI十连测 第一测 T1
思路:首先考虑t=1的情况,t等于1,那么所有位置的颜色相同,我们不用考虑概率的问题,那么,k+d*x在模d下都相等,我们考虑预处理一个数组s[i][j],代表d为i,起始位置为j的等差数列的和,这个 ...
- QTableView使用HTML显示富文本
对于QTableView中的显示,我们前面介绍过很多种,其中包括:文本.进度条.复选框等,今天我们介绍一下关于富文本的显示. 可能绝大多数小伙伴会通过QAbstractTableModel中的data ...
- 使用Qt编写服务器端程序(包括Http传输服务器端)的方法
使用Qt编写客户端的程序的示例或demo较多,但是编写服务器端程序的demo很少.当然,服务器端的程序一般不需要带界面,这点我们可以理解.不过有些时候我们还是需要使用Qt编写一个简单的测试用的服务器代 ...