http://poj.org/problem?id=2524

这道题就是并查集。

 #include<cstdio>
#include<cstring>
#include<iostream>
#define maxn 50010
using namespace std;
int a[maxn];
int n,m;
void init()
{
for(int i=;i<=n;i++)
a[i]=i;
}
int find1(int x)
{
if(x!=a[x])
a[x]=find1(a[x]);
return a[x];
}
void merge1(int x,int y)
{
int fx=find1(x);
int fy=find1(y);
if(fx!=fy){
a[fx]=fy;
n--;
}
}
int main()
{
int a,b,t=;
while(scanf("%d%d",&n,&m)&&n&&m){
init();
for(int i=;i<=m;i++){
scanf("%d%d",&a,&b);
merge1(a,b);
}
t++;
printf("Case %d: ",t);
printf("%d\n",n);
}
return ;
}

Ubiquitous Religions的更多相关文章

  1. poj 2524:Ubiquitous Religions(并查集,入门题)

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23997   Accepted:  ...

  2. POJ 2524 Ubiquitous Religions

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 20668   Accepted:  ...

  3. Ubiquitous Religions 分类: POJ 2015-06-16 17:13 11人阅读 评论(0) 收藏

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 26678   Accepted: ...

  4. poj 2524 Ubiquitous Religions(宗教信仰)

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 30666   Accepted: ...

  5. POJ2524——Ubiquitous Religions

    Ubiquitous Religions Description There are so many different religions in the world today that it is ...

  6. POJ 2524 :Ubiquitous Religions

    id=2524">Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 231 ...

  7. 【原创】poj ----- 2524 Ubiquitous Religions 解题报告

    题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 6 ...

  8. POJ 2524 Ubiquitous Religions 解题报告

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 34122   Accepted:  ...

  9. [ACM] POJ 2524 Ubiquitous Religions (并查集)

    Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 23093   Accepted:  ...

  10. poj 2524 Ubiquitous Religions 一简单并查集

    Ubiquitous Religions   Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 22389   Accepted ...

随机推荐

  1. bootstrap 仿实例

    bootstrap实现一个网页 html文件 <!DOCTYPE html> <html> <head lang="en"> <meta ...

  2. 页游AS客户端架构设计历程记录

    以下是一个只用JAVA做过服务器架构的程序员做的AS客户端架构,希望大家能推荐好的框架和意见,也求AS高程们的引导,等到基本功能成形后,低调开源,框架可以支持一个中度型页游的开发,本文不断更新中... ...

  3. PHP学习路径

    php学习大致可分为三个阶段: 第一阶段:基础知识,页面布局. 学习内容:html.div+css.js. 学习目标:div+css设计. 阶段二:php核心知识和数据库交互. 学习内容:php核心知 ...

  4. ThinkPHP pdo连接Oracle的配置写法,提示报错

    'DB_TYPE' => 'pdo', // 数据库类型 'DB_USER' => 'user101', // username 'DB_PWD' => 'zb~!@#$%', // ...

  5. Java程序员也应该知道的系统知识系列之(网卡,cpu,内存,硬盘,虚拟化)

    https://yq.aliyun.com/articles/1718?spm=5176.100240.searchblog.16.UaGd04 https://yq.aliyun.com/artic ...

  6. linux 下 apt命令集详解

    apt命令用法 packagename指代为软件包的名称 apt-get update 在修改/etc/apt/sources.list或/etc/apt/preferences之後运行该命令.此外您 ...

  7. Adobe DreamweaverCS6安装及破解(序列号+破解补丁)

    一:安装 1) Adobe DreamweaverCS6中文版下载地址:Adobe DreamweaverCS6中文版下载 2)Adobe DreamweaverCS6安装及破解说明下载地址:Adob ...

  8. 标量类型(scalar)

    (ISO C11 §6.2.5) Arithmetic types and pointer types are collectively called scalar types. Array and ...

  9. Tempdb对SQL Server性能的影响

    转载文章,原文地址:http://www.cnblogs.com/laodao1/archive/2010/04/15/1712395.html1.SQL Server系统数据库介绍 SQL Serv ...

  10. CTE的使用

    CTE在SQL2005后的版本提供,丰富了查询的表现形式,下面我们慢慢来看下CTE都能干什么 1.自我递归 ;WITH myaa AS ( SELECT num=1 UNION ALL SELECT ...