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 ...
随机推荐
- 【BZOJ 3343 】 分块
3343: 教主的魔法 Description 教主最近学会了一种神奇的魔法,能够使人长高.于是他准备演示给XMYZ信息组每个英雄看.于是N个英雄们又一次聚集在了一起,这次他们排成了一列,被编号为1. ...
- 【mysql的设计与优化专题(1)】ER图,数据建模与数据字典
需求分析是做项目中的极为重要的一环,而作为整个项目中的'血液'--数据,更是重中之重.viso,workbench,phpmyadmin等软件可以帮我们更好的处理数据分析问题. ER图 E-R方法是& ...
- 分布式事务的管理--atomikos
在一些业务场景及技术架构下,跨库的事务时不可避免的,这时候如何统一管理事务,保证事务的强一致性是整个系统稳定.可用基石.一些中间件如tuxedo.cics就是凭借这个能力占据了金融.电信.银行等很大的 ...
- WPF博客地址分享
http://www.cnblogs.com/chenxizhang/archive/2010/03/25/1694604.html http://www.cnblogs.com/lzhp/archi ...
- QMenu的个性化定制
经常使用菜单,菜单的定制相当重要,普通的样式设置不难,一般需求足以实现(QMenu + QAction).如果要足够个性,则需要进行一定的定制. 说起定制,其实也是利用Qt中现成的组件进行组装 ...
- CentOS 6.4 编译安装Mysql 5.6.14
概述: CentOS 6.4下通过yum安装的MySQL是5.1版的,比较老,所以就想通过源代码安装高版本的5.6.14. 正文: 一:卸载旧版本 使用下面的命令检查是否安装有MySQL Server ...
- 2013ACM省赛题目
地址就贴这一个吧 都在附近 当时回来也没做做 一伤心了 二是当时实在太弱了 先补两道DP E题的区间DP dp[i][j] 截止到i位置以字母j为结束的上升序列 正序 逆序各来一遍 再循环一遍保存一 ...
- 解决windows下vim方向键变成 ABCD 的问题
一.问题描述: windows下面要安装git --> 安装了 msys2 -->安装并更新了 vim(7.4),然后在使用过程中发现vim不能使用 BACKSPACE 键,按方向键会打 ...
- Cacti 'graph_xport.php' SQL注入漏洞
漏洞版本: Cacti < 0.8.8b 漏洞描述: Bugtraq ID:66555 Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具. Cact ...
- ☀【Grunt】插件
Grunt Pluginshttp://gruntjs.com/plugins grunt-contrib-sass sass: { compile: { files: { 'css/core.css ...