题意:

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)

思路:

并查集,判断好各种可能的情况。

代码:

int n,k,m;
int fa[100005], ability[100005]; int findFa(int x){
if(fa[x]==x)
return fa[x];
int t=fa[x];
fa[x]=findFa(fa[x]);
ability[x] = min( ability[x],ability[t] );
return fa[x];
} int main(){ while(scanf("%d%d%d",&n,&k,&m)!=EOF){
rep(i,0,n-1){
fa[i]=i;
ability[i]=inf;
} rep(i,1,k){
int rate,belongTo;
scanf("%d%d",&rate,&belongTo);
ability[belongTo]=min( ability[belongTo],rate );
}
while(m--){
char ope[5];
scanf("%s",ope);
if(ope[0]=='A'){
int x,y;
scanf("%d%d",&x,&y);
int faTemp=findFa(y);
if(y!=faTemp){
puts("Reject");
}else{
ability[faTemp]=min( ability[faTemp],x );
puts("Accept");
}
}
else if(ope[0]=='M'){
int x,y;
scanf("%d%d",&x,&y);
int fx=findFa(x);
int fy=findFa(y);
if(fx!=x || fy!=y || fx==fy){
puts("Reject");
}else{
ability[fx]=min( ability[fx],ability[fy] );
fa[fy]=fx;
puts("Accept");
}
}
else{
int x;
scanf("%d",&x);
int fx=findFa(x);
if(x!=fx){
printf("Company %d is a part of company %d.\n",x,fx);
}
else{
if(ability[x]==inf){
printf("Company %d is empty.\n",x);
}else{
printf("Lowest rate: %d.\n",ability[x]);
}
}
}
}
puts(""); } return 0;
}

最新文章

  1. JAVA的模式对话框和非模式对话框
  2. android应用安全——(数据抓包)跟踪监控android数据包
  3. Neutron 理解 (1): Neutron 所实现的虚拟化网络 [How Netruon Virtualizes Network]
  4. 洛谷P3390 【模板】矩阵快速幂
  5. bnuoj 24251 Counting Pair
  6. 黑马程序员:Java编程_String
  7. 蓝牙(Profile)构成
  8. Java中的栈:java.util.Stack类
  9. js实现楼层效果
  10. memcpy源代码
  11. reincarnation server
  12. java正则表达式获取指定HTML标签的指定属性值
  13. seq语句随笔
  14. LeetCode之“链表”:Linked List Cycle &amp;&amp; Linked List Cycle II
  15. [物理学与PDEs]第1章第2节 预备知识 2.2 Ampere-Biot-Savart 定律, 静磁场的散度与旋度
  16. K-means算法的matlab程序(初步)
  17. 计算机基础+python安装注意问题+python变量介绍
  18. mysql 在update中实现子查询的方式
  19. webapi中使用swagger
  20. 洛谷 P2431 正妹吃月饼 解题报告

热门文章

  1. 基于Typora的Latex代码书写并移植到word中
  2. mysql 选取操作日志(mysql-bin.0000恢复数据)
  3. dede调用数据时,字符串替换函数使用
  4. ecshop后台设置模板的地方显示自己新建模板的操作界面
  5. python 建站教程
  6. 『Python』matplotlib实现GUI效果
  7. 10分钟教你使用Picgo+GitHub+ jsDelivr搭建CDN加速免费图床
  8. 鸿蒙内核源码分析(挂载目录篇) | 为何文件系统需要挂载 | 百篇博客分析OpenHarmony源码 | v65.01
  9. 一个故事看懂CPU的TLB
  10. JQuery EasyUI 结合ztrIee的后台页面开发