HDU 3974 Assign the task 并查集
来源:互联网 发布:数据库系统工程师书籍 编辑:程序博客网 时间:2024/06/05 15:52
http://acm.hdu.edu.cn/showproblem.php?pid=3974
题目大意:
一个公司有N个员工,对于每个员工,如果他们有下属,那么他们下属的下属也是他的下属。
公司会给员工安排任务,分配给一个员工后,他也会把这个任务分配给下属。被分配到任务的人立刻停止 当前在做的工作,接受新的任务。
对于给定的M个操作
C x 输出编号为x的任务
T x y 分配任务y给x
思路:
并查集的实现,分配我们只记录在上司结点里,只不过查询的时候要把它的所有上司全部找一遍。
#include<cstdio>#include<iostream>using namespace std;const int MAXN=50001;int fa[MAXN];int val[MAXN];int time[MAXN];int main(){int T;scanf("%d",&T);for(int ri=1;ri<=T;ri++){int n;scanf("%d",&n);for(int i=1;i<=n;i++){fa[i]=i;val[i]=-1;time[i]=-1;}for(int i=1;i<n;i++){int a,b;scanf("%d%d",&a,&b);fa[a]=b;}printf("Case #%d:\n",ri);int m,cnt=0;scanf("%d",&m);char cmd;while(m--){cin>>cmd;if(cmd=='C'){int x;scanf("%d",&x);int cur=x,ans=val[cur],lastt=-1;while(cur != fa[cur]){if(time[cur] > lastt)//后加入的{lastt=time[cur];ans=val[cur];}cur=fa[cur];}if(time[cur] > lastt)//后加入的{lastt=time[cur];ans=val[cur];}printf("%d\n",ans);}else{int x,y;scanf("%d%d",&x,&y);val[x]=y;time[x]=cnt++;}}}return 0;}
5 0
- HDU 3974 Assign the task (并查集改编)
- HDU 3974 Assign the task 并查集
- HDU 3974 Assign the task(并查集)
- HDU 3974 Assign the task(树 并查集)
- HDU 3974 Assign the task [并查集扩展]
- HDU 3974 Assign the task(并查集)
- 并查集--HDU 3974Assign the task--带权
- HDU 3974 Assign the task 并查集解法
- Assign the task (并查集)
- Assign the task (并查集)
- HDU 3974 Assign the task (并查集&线段树)
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- HDU 3974 Assign the task
- HDU 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- 两位数乘法的速算方法(二)
- JavaSE —— 标准输入/输出
- cocostudio使用的一些心得
- 百度编辑器配置
- 向 OpenStack 贡献您的代码
- HDU 3974 Assign the task 并查集
- 使用PHP进行网页数据抓取小结
- 在 JScript 中使用 ADO
- 语音特征参数MFCC计算的详细过程
- 如何提交代码给openstack
- 研究生期间有关语音识别方面资料的收集
- Weblogic性能调优基本方案
- sniffer原理
- cocos2d-x 动作与动画