Problem Description
When ALPC42 got to a panzer brigade, He was asked to build software to help them regroup the battalions or companies. As the tradition of army, soldiers are rated according his or her abilities, taking the rate as an integer. The fighting capacity of a company is determined by the soldier in this company whose rate is lowest. Now the recruits those rated are coming and join to their companies according to the order form HQ. With the coming of new recruits, a big regroup action reached, asking to merge some companies into one. The designation of a company, however, will not be canceled, but remain for memorialize what the company is done, means the designation of the company is still exist, but the company is gone, so it is unable to ask recruits to join this company, or merge the company into others. A strange thing is, the orders sometimes get wrong, send newbie to a company which is already merged into another, or mentioned some only-designation-existed companies. Such order could be rejected. The brigadier wants to know every change of each order, so the program should able to report the status of every order, telling whether it is accept, and can query the fighting capacity of specified company. (To simplify, companies are numbered from 0 to n-1
 
Input
There may be several test cases. For each case, the integers in first line, n, k, m, telling that there are n companies, k soldiers already, and m orders needs be executed. (1<=n ,k ,m<=100000). Then k lines with two integers R and C for each, telling a soldier with rate R is now in company C Then m lines followed, containing 3 kinds of orders, in upper case:   AP x y A recruit with ability rate x were asked to join company y. (0<=x<2^31, 0<=y<n)
  MG x y Company x and company y is merged. The new company is numbered as x. (0<=x, y<n)
  GT x Report the fighting capacity of company x. (0<=x<n)
 
Output
For each order there is exact one line to report the result. For AP and MG order, print “Accept” if it is able to be done, and execute it, or “Reject” if it is an illegal order. For GT order, if company x is still exist (not merged into others), print as “Lowest rate: y.” which y is the minimal rate of soldiers in this company. If there is no one in this company, tell "Company x is empty." If company x is already merged into others, print "Company x is a part of company z." z is the company where the company x is in. Print a blank line after each case
 
Sample Input
5 5 10
5 0
5 1
5 2
5 1
5 0
GT 0
GT 3
AP 3 3
GT 3
GT 4
MG 3 4
GT 4
MG 1 3
GT 4
GT 1
 
Sample Output
Lowest rate: 5.
Company 3 is empty.
Accept
Lowest rate: 3.
Company 4 is empty.
Accept
Company 4 is a part of company 3.
Accept
Company 4 is a part of company 1.
Lowest rate: 3.
 
题意:有n个公司,有k个人,会给出k个人的能力值和处于哪个公司。然后有m个操作,分别有3种不同的操作
AP x y 能力值为x的人加入到y公司中
MG x y x公司和y公司合并
GT x 查询x公司中能力值最小值
如果某个公司已经被别的公司合并了,则其他人不能加入此公司,此公司也不能再跟其他公司合并,对于AP和MG操作,如果可行则输出Accept,并执行此
操作,不能则输出Reject,忽略此操作。对于GT操作,如果此公司未被合并,则输出此公司中能力值最小值Lowest rate: 能力值. ,此公司没人则输出
Company 编号 is empty.否则输出Company 此公司编号 is a part of company 合并的公司编号.
 
解析:很明显的种类并查集,在合并的过程中更新一下能力值。这道题有一个坑点,如果x==y则直接输出Reject。。。。。。。。
 

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
typedef __int64 LL;
const LL INF=1e12+;
const int maxn=;
LL Min(LL a,LL b){ return a<b?a:b; }
int N,K,M;
LL val[maxn];
int d[maxn];
int root(int a)
{
if(d[a]==a) return a;
int t=d[a];
d[a]=root(d[a]);
//val[a]=Min(val[a],val[t]);
return d[a];
}
void FunA()
{
LL x;
int y;
scanf("%lld%d",&x,&y);
int ra=root(y);
if(ra!=y) printf("Reject\n");
else
{
printf("Accept\n");
val[ra]=Min(val[ra],x);
}
}
void FunM()
{
int x,y;
scanf("%d%d",&x,&y);
if(x==y){ printf("Reject\n"); return; }
int ra=root(x);
int rb=root(y);
if(ra!=x||rb!=y) printf("Reject\n");
else
{
d[rb]=ra;
val[ra]=Min(val[ra],val[rb]);
printf("Accept\n");
}
}
void FunG()
{
int x;
scanf("%d",&x);
int ra=root(x);
if(ra!=x) printf("Company %d is a part of company %d.\n",x,ra);
else if(val[ra]==INF) printf("Company %d is empty.\n",ra);
else printf("Lowest rate: %lld.\n",val[ra]);
}
int main()
{
while(scanf("%d%d%d",&N,&K,&M)!=EOF)
{
LL r;
int c;
for(int i=;i<maxn;i++) val[i]=INF,d[i]=i;
for(int i=;i<=K;i++)
{
scanf("%lld%d",&r,&c);
val[c]=Min(val[c],r);
}
char op[];
while(M--)
{
scanf("%s",op);
if(op[]=='A') FunA();
else if(op[]=='M') FunM();
else FunG();
}
printf("\n");
}
return ;
}


Hdu2860-Regroup(种类并查集)的更多相关文章

  1. NOI2001|POJ1182食物链[种类并查集 向量]

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 65430   Accepted: 19283 Description ...

  2. NOIP2010关押罪犯[并查集|二分答案+二分图染色 | 种类并查集]

    题目描述 S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨气值”(一个正整数值)来表示 ...

  3. POJ1703Find them, Catch them[种类并查集]

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42416   Accepted: ...

  4. poj1417(种类并查集+dp)

    题目:http://poj.org/problem?id=1417 题意:输入三个数m, p, q 分别表示接下来的输入行数,天使数目,恶魔数目: 接下来m行输入形如x, y, ch,ch为yes表示 ...

  5. poj1733(种类并查集+离散化)

    题目链接: http://poj.org/problem?id=1733 题意: 输入n表示有一个长度为n的0,1字符串, m表示接下来有m行输入, 接下来的m行输入中x, y, even表示第x到第 ...

  6. poj 1182:食物链(种类并查集,食物链问题)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44168   Accepted: 12878 Description ...

  7. pku 1703(种类并查集)

    题目链接:http://poj.org/problem?id=1703 思路;个人觉得本质上还是和带权并查集一样的,只不过多了一个MOD操作,然后就是向量关系图稍微改动一下就变成种类并查集了,对于本题 ...

  8. hdu 3038 How Many Answers Are Wrong(种类并查集)2009 Multi-University Training Contest 13

    了解了种类并查集,同时还知道了一个小技巧,这道题就比较容易了. 其实这是我碰到的第一道种类并查集,实在不会,只好看着别人的代码写.最后半懂不懂的写完了.然后又和别人的代码进行比较,还是不懂,但还是交了 ...

  9. 【进阶——种类并查集】hdu 1829 A Bug's Life (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany

    先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组 ...

随机推荐

  1. openSourceEvent

    开放源码(开源)的精神在于使用者可以使用.复制.散布.研究和改进软件.这可以追溯到20世纪60年代,至今已有半个世纪了.虽然下面所列举的不都是专门的开源产品,但还是在开源发展的进程中有着巨大的影响. ...

  2. IOS深入学习(12)之Archiving

    1 前言 本文介绍的是一个归档解档方法,也是编码和解码时候所做的事情,和如何进行,编码和归档其实就是将对象关系转化为字节流并且归档为特殊的文件,解码和解档是逆过程. 英文原文:http://blog. ...

  3. c指针点滴4-指针的值

    #include <stdio.h> #include <stdlib.h> void main() { ; int *p = &num; //double *p1 = ...

  4. <s:iterator> 序号

    <s:iterator />的序号,解决这个问题有两种办法. 方法一:通过set标签实现: <s:set name="a" value=1/> <s: ...

  5. iphone UIScrollView缩放

    allImageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; allImageScrol ...

  6. 【公告】CSDN个人空间将于2014年4月20日全新改版上线

    尊敬的用户:   你们好!           CSDN个人空间将在2014年4月20日全新改版上线!        CSDN个人空间是2008年8月推出的服务,致力于给广大用户提供在线技术分享和资料 ...

  7. HTTP协议具体解释

    HTTP是一个属于应用层的面向对象的协议.因为其简捷.高速的方式.适用于分布式超媒体信息系统. 它于1990年提出,经过几年的使用与发展,得到不断地完好和扩展.眼下在WWW中使用的是HTTP/1.0的 ...

  8. 软件project(五)——可行性研究

    一.目的 用最小的代价高效率的确定问题是否可以解决. 不是去解决这个问题,而是确定问题是否值得去解决.进行可行性研究简化了系统分析和系统设计的过程. 二.任务 (1)进一步分析问题定义. (2)分析员 ...

  9. C#工厂模式代码实例

    此处示例为一个简易计算器工厂模式的实现. 创建类库,名为CalcLib,我把计算功能全部放在这个类库中. 首先,创建一个抽象的计算器算法父类,如下: /// <summary> /// 计 ...

  10. 常用aliyun公共资源列表

    公共DNS      223.5.5.5      223.6.6.6   源软件镜像站点      mirros.aliyun.com   NTP服务器 unix like      ntp1-7. ...