Ubiquitous Religions
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的更多相关文章
- poj 2524:Ubiquitous Religions(并查集,入门题)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23997 Accepted: ...
- POJ 2524 Ubiquitous Religions
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 20668 Accepted: ...
- Ubiquitous Religions 分类: POJ 2015-06-16 17:13 11人阅读 评论(0) 收藏
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 26678 Accepted: ...
- poj 2524 Ubiquitous Religions(宗教信仰)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 30666 Accepted: ...
- POJ2524——Ubiquitous Religions
Ubiquitous Religions Description There are so many different religions in the world today that it is ...
- POJ 2524 :Ubiquitous Religions
id=2524">Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 231 ...
- 【原创】poj ----- 2524 Ubiquitous Religions 解题报告
题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS Memory Limit: 6 ...
- POJ 2524 Ubiquitous Religions 解题报告
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 34122 Accepted: ...
- [ACM] POJ 2524 Ubiquitous Religions (并查集)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 23093 Accepted: ...
- poj 2524 Ubiquitous Religions 一简单并查集
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 22389 Accepted ...
随机推荐
- Demo_玩家移动(主要注意动画的设置)
using UnityEngine; using System.Collections; public class NewPlayerMove : MonoBehaviour { private fl ...
- QT程序库
实际上,QT不仅仅是一个巨大的程序库,而是7个程序库,还包括许多使用工具,qmake是其中的一个.如今,术语GUI工具包代表的东西的用途不再仅仅是系统提供的那么一个小部分(GUI界面).尤其是QT ...
- JQ插件之imgAreaSelect实现对图片的在线截图功能(java版)
前言:在做网站的时候经常用的功能就是,用户上传图片对自己上传的图片进行截图,DIV自己的头像.或者上传幻灯片大图进行DIV设置小图. 解决方案:目前我知道的解决方案有两个如下: 一.fla ...
- 从 ReactiveCocoa 中能学到什么?不用此库也能学以致用
从知道ReactiveCocoa开始就发现对这个库有不同的声音,上次参加<T>技术沙龙时唐巧对在项目中已全面使用FRP的代码家提出为什么这种编程模型出现了这么长时间怎么像ReactiveC ...
- OSX10.11 CocoaPods 升级总结
本文不会讨论CocoaPods的各种使用技巧以及各种原理,只是简单记录一下在升级过程中遇到的问题,如果使用中有各种问题来欢迎交流. Podfile.loc 文件变化 前几天一个小伙更新了CocoaPo ...
- python学习之成员信息增删改查
主要实现了成员信息的增加,修改,查询,和删除功能,写着玩玩,在写的过程中,遇到的问题,旧新成员信息数据的合并,手机号和邮箱的验证,#!/usr/bin/env python# coding=utf8# ...
- HTML-点击收藏功能模块
先上效果图: 功能简单: 附上源码以及注解 <div class="info-attribute" id="collect"> <input ...
- document.all用法
document.all用法 一. document.all是页面内所有元素的一个集合.例如: document.all(0)表示页面内第一个元素二.document.all可以判断浏览器 ...
- HTML 详细介绍
什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不是一种编程语言,而是一种标记语言 (ma ...
- c#中去掉字符串空格方法
(1)Trim方法 string tt=" aaa "; tt=tt.Trim() 去字符串首尾空格的函数 tt=tt.TrimEnd() 去掉字符串尾空格 tt= ...