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&#39;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&#39;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&#39;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&#39;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 ...
随机推荐
-
如何用perl将表格中不同列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据进行拼凑,然后将拼凑后的数据用“|”连接在一起. 表格内容如下: 员工号码 员工姓名 职位 入职日期 1001 张三 销售 1980/12/ ...
-
wp8 入门到精通 ImageCompress 图片压缩
//实例化选择器 PhotoChooserTask photoChooserTask = new PhotoChooserTask(); BitmapImage bimg; int newPixelW ...
-
【leetcode❤python】21. Merge Two Sorted Lists
#-*- coding: UTF-8 -*- # Definition for singly-linked list.# class ListNode(object):# def __init ...
-
apache+php+mysql常见集成环境安装包
http://www.thinksaas.cn/group/topic/33/ apache+php+mysql是常见php环境,在windows下也称为WAMP,对于初学者自选版本搭建总是会遇到一些 ...
-
git分支的使用
本文章假定你已经接触了一些git的基本概念和基本的操作知识 这里先贴出关于分支的一些常用命令 git branch /*查看所有分支*/git branch <branch-name> / ...
-
Android - FEATURE_NO_TITLE
Android设置无标题的方法 在onCreate()中写入: requestWindowFeature(Window.FEATURE_NO_TITLE); 例如: protected void on ...
-
Python实战之用类的静态方法实现登录验证
#!usr/bin/env Python3 # -*-coding:utf-8-*- __author__="William" #define a class,just to le ...
-
BZOJ_4765_普通计算姬_分块+dfs序+树状数组
BZOJ_4765_普通计算姬_分块 Description "奋战三星期,造台计算机".小G响应号召,花了三小时造了台普通计算姬.普通计算姬比普通计算机要厉害一些 .普通计算机能 ...
-
[Swift]LeetCode341. 压平嵌套链表迭代器 | Flatten Nested List Iterator
Given a nested list of integers, implement an iterator to flatten it. Each element is either an inte ...
-
sbt安裝與配置
官方下載地址:https://www.scala-sbt.org/download.html?spm=a2c4e.11153940.blogcont238365.9.42d147e0iF8dhv 解压 ...