HDU 2860 Regroup(并查集)

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个军旅 ,现在有m个兵,有k个操作,
对于接下来的m行,表示战斗力为x的兵现在在军旅y中,对于三种操作:
1、AP:让一个战斗力为x的兵加入军旅y中。
2、GT:查询军旅x。如果军旅x中没兵输出空,如果军队有兵并且自己没有被其他军队管辖,那么输出军队中战斗力最渣的战斗力值。如果军队被其他军队所管辖,那么输出其管辖他的军旅编号。
3、MG:让军旅y置于军旅x之下管辖。
这里有一个条件,如果当前军队没有被其他军队管辖的情况下,是可以有新兵加入的,也可以有其他军队加入这个军队的,不过如果当前军队已经被其他军队管辖了,那么新兵是进不来的;军旅也一样,如果当前军旅已经被其他军旅管辖了,那么这个军旅也不能再让其他军旅管辖了。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define INF 0x3f3fffff
int father[100010];
int minn[100010];
int getfather(int x)
{
    if(x != father[x])
        father[x] = getfather(father[x]);
    return father[x];
}
int main()
{
    char st[2];
    int n,m,k,i,a,b,c,d;
    while(~scanf("%d%d%d",&n,&m,&k))
    {
        for(i=0; i<n; i++)
        {
            father[i]=i;
            minn[i]=INF;
        }
        for(i=0; i<m; i++)
        {
            scanf("%d%d",&a,&b);
            minn[b]=min(minn[b],a);
        }
        while(k--)
        {
            scanf("%s",&st);
            if(st[0]=='G')
            {
                scanf("%d",&c);
                if(father[c]==c)
                {
                    if(minn[c]!=INF)
                        printf("Lowest rate: %d.\n",minn[c]);
                    else
                        printf("Company %d is empty.\n",c);
                }
                else
                    printf("Company %d is a part of company %d.\n",c,getfather(c));
            }
            else if(st[0]=='A')
            {
                scanf("%d%d",&c,&d);
                if(father[d]==d)
                {
                    minn[d]=min(minn[d],c);
                    printf("Accept\n");
                }
                else
                    printf("Reject\n");
            }
            else
            {
                scanf("%d%d",&c,&d);
                if(father[c]==c&&father[d]==d&&c!=d)
                {
                    father[d]=c;
                    minn[c]=min(minn[c],minn[d]);
                    printf("Accept\n");
                }
                else
                    printf("Reject\n");
            }
        }
        printf("\n");
    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
未来社区的建设背景和需求分析指出,随着智能经济、大数据、人工智能、物联网、区块链、云计算等技术的发展,社区服务正朝着数字化、智能化转型。社区服务渠道由分散向统一融合转变,服务内容由通用庞杂向个性化、服务导向转变。未来社区将构建数字化生态,实现数据在线、组织在线、服务在线、产品智能和决策智能,赋能企业创新,同时注重人才培养和科研平台建设。 规划设计方面,未来社区将基于居民需求,打造以服务为中心的社区管理模式。通过统一的服务平台和应用,实现服务内容的整合和优化,提供灵活多样的服务方式,如推送式、订阅式、热点式等。社区将构建数据与应用的良性循环,提高服务效率,同时注重生态优美、绿色低碳、社会和谐,以实现幸福民生和产业发展。 建设运营上,未来社区强调科学规划、以人为本,创新引领、重点突破,统筹推进、整体提升。通过实施院落+社团自治工程,转变政府职能,深化社区自治法制化、信息化,解决社区治理中的重点问题。目标是培养有活力的社会组织,提高社区居民参与度和满意度,实现社区治理服务的制度机制创新。 未来社区的数字化解决方案包括信息发布系统、服务系统和管理系统。信息发布系统涵盖公共服务类和社会化服务类信息,提供政策宣传、家政服务、健康医疗咨询等功能。服务系统功能需求包括办事指南、公共服务、社区工作参与互动等,旨在提高社区服务能力。管理系统功能需求则涉及院落管理、社团管理、社工队伍管理等,以实现社区治理的现代化。 最后,未来社区建设注重整合政府、社会组织、企业等多方资源,以提高社区服务的效率和质量。通过建立社区管理服务综合信息平台,提供社区公共服务、社区社会组织管理服务和社区便民服务,实现管理精简、高效、透明,服务快速、便捷。同时,通过培育和发展社区协会、社团等组织,激发社会化组织活力,为居民提供综合性的咨询和服务,促进社区的和谐发展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值