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. continuous integration and continuous deployment in DW/BI

    deployment methodIn Redshift1, Deploy process: Drop and Refresh the view, Drop table, Create an empt ...

  2. geektool--一款很geek的工具

    2016/12/18 今天尝试一款很geek的工具 geektool 听名字就超级geek有木有 get it geektool website 从官网直接下载app,一键傻瓜式安装. use it ...

  3. iOS中@class #import #include 简介

    [转载自:http://blog.csdn.net/chengwuli125/article/details/9705315] 一.解析        很多刚开始学习iOS开发的同学可能在看别人的代码 ...

  4. WCF:如何将net.tcp协议寄宿到IIS

    1 部署IIS 1.1 安装WAS IIS原本是不支持非HTTP协议的服务,为了让IIS支持net.tcp,必须先安装WAS(Windows Process Activation Service),即 ...

  5. android——api

    一.1.复用首页做法—从Intent中获取”com.example.android.apis.Path”.根据这个结合PackageManger获得的Activities来展示不同等级的List界面( ...

  6. iOS:编译错误Undefined symbols for architecture i386: _OBJC_CLASS_$_XXX&quot;, referenced from: error

    Undefined symbols for architecture i386: _OBJC_CLASS_$_XXX", referenced from: error 这个意思为无法找到名为 ...

  7. GDB调试技巧

    1. 查看内存分布 (gdb) info proc mappings 2. 对于类的调试,先通过行号来设断点, 比如:(gdb) b TcpConnection.cc:63 3. 打印数组的内容 (g ...

  8. Mysql update error: Error Code: 1175. You are using safe update mode and you tried to update a table

    Mysql update error: Error Code: 1175. You are using safe update mode and you tried to update a table ...

  9. NYOJ 47过河问题

    主要思路:先排序.有两种可能是最小的情况,一种是让最小的去带着最大的过去,然后最小的再回来,还有一种就是先最小的和第二小的一块过去, 然后最小的回来,让最大的和第二大的过去,接着第二小的回来,第二小和 ...

  10. shijan

    1.<?php 2. $zero1=date(“y-m-d h:i:s”); 3. $zero2=”2010-11-29 21:07:00′; 4. echo “zero1的时间为:”.$zer ...