HDU 3974 Assign the task(树 并查集)
题意 公司中有n个员工 除了boss 每个员工都有自己的上司 自己下属的下属也是自己的下属 当给一个员工分配任务时 这个员工会把任务也分配到自己的所有下属 每个员工都只做最后一个被分配的任务 对于每个C x 输出员工x正在做的任务 没有就输出-1
把员工的关系数建成类似并查集的结构 把每个直接分配任务的员工的任务和任务分配时间保存起来 查询时只要找这个员工所有父节点中最晚分配的任务
#include <bits/stdc++.h>
using namespace std;
const int N = 50005;
struct employee{int task, t;
} e[N];
int par[N];int main()
{int cas, a, b, n, m;char op[5];scanf("%d", &cas);for(int k = 1; k <= cas; ++k){printf("Case #%d:\n", k);memset(par, -1, sizeof(par));scanf("%d", &n);for(int i = 1; i < n; ++i){e[i].t = e[i].task = 0;scanf("%d%d", &a, &b), par[a] = b;}e[n].t = e[n].task = 0;scanf("%d", &m);int t = 0, last, ans;while(m--){scanf("%s%d", op, &a);if(op[0] == 'C'){last = 0;//所有祖先节点最晚任务的时间while(a != -1){if(e[a].t > last)last = e[a].t, ans = e[a].task;a = par[a];}printf("%d\n", last ? ans : -1);}else{scanf("%d", &b);e[a].task = b, e[a].t = ++t;}}}return 0;
}
//Last modified : 2015-04-22 20:48
Assign the task
The company usually assigns some tasks to some employees to finish.When a task is assigned to someone,He/She will assigned it to all his/her subordinates.In other words,the person and all his/her subordinates received a task in the same time. Furthermore,whenever a employee received a task,he/she will stop the current task(if he/she has) and start the new one.
Write a program that will help in figuring out some employee’s current task after the company assign some tasks to some employee.
For each test case:
The first line contains an integer N (N ≤ 50,000) , which is the number of the employees.
The following N - 1 lines each contain two integers u and v, which means the employee v is the immediate boss of employee u(1<=u,v<=N).
The next line contains an integer M (M ≤ 50,000).
The following M lines each contain a message which is either
"C x" which means an inquiry for the current task of employee x
or
"T x y"which means the company assign task y to employee x.
(1<=x<=N,0<=y<=10^9)
HDU 3974 Assign the task(树 并查集)相关推荐
- HDU - 3974 Assign the task (线段树 + dfs序)
HDU - 3974 题意:有个公司有一些关系,每个人(除了boss)都有且仅有一个上司,这就是一棵树的关系,然后会有一些操作,C i,询问第i个人现在的任务,T x y,把y任务给x, 给x相当于给 ...
- HDU 3974 Assign the task(DFS序+线段树单点查询,区间修改)
描述 There is a company that has N employees(numbered from 1 to N),every employee in the company has a ...
- HDU 3974 Assign the task(dfs时间戳+线段树成段更新)
题意:给定点的上下级关系,规定假设给i分配任务a.那么他的全部下属.都停下手上的工作,開始做a. 操作 T x y 分配x任务y,C x询问x的当前任务: Sample Input 1 5 4 3 3 ...
- HDU - 3974 Assign the task (DFS建树+区间覆盖+单点查询)
题意:一共有n名员工, n-1条关系, 每次给一个人分配任务的时候,(如果他有)给他的所有下属也分配这个任务, 下属的下属也算自己的下属, 每次查询的时候都输出这个人最新的任务(如果他有), 没有就输 ...
- HDU 1512 Monkey King 左偏树 + 并查集
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1512 题意:有n个猴子,一开始每个猴子只认识自己.每个猴子有一个力量值,力量值越大表示这个猴子打架越厉害. ...
- 可持久化线段树【主席树】可持久化并查集【主席树+并查集】
笼统的主席树原理 众所周知, 主席树是可以持久化的, 换言之你能知道你所维护信息的所有历史状态. 主席树是这样做的: 1. 首先建一颗朴素的线段树,代表初始状态 (下图黑色) , 也就是第0次操作后的 ...
- HDU 1512 Monkey King(左偏树+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1512 题 意: 有n个猴子,一开始每个猴子只认识自己.每个猴子有一个力量值,力量值越大表示 ...
- HDU 1272 - 小希的迷宫(并查集判树)
目录 Problem Description C++代码 Problem Description 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来 ...
- HDU 3047 Zjnu Stadium (带权并查集)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=3047 题目: Problem Description In 12th Zhejiang College ...
最新文章
- Ubuntu E: Unable to locate package错误解决办法
- hdu4020简单想法题
- 2003系统管理实战 web的优化 安全
- HaaS UI小程序
- t3软件怎么生成报表_临沂用友畅捷通T3财务通软件财税一体化
- linux下恢复误删文件
- 建阳有计算机学校吗,建阳有哪几所中专技校
- 结构体04:结构体嵌套结构体
- Mybatis-plus 多表联查实现(非手写sql)
- 《处理器虚拟化技术》
- 【华为_数通】常用命令备忘
- C. Balanced Stone Heaps和P2440 木材加工
- 千牛2015卖家版官方电脑版
- 12306自动抢票软件
- 小鸟云服务器怎么进行启动和关机?
- catic备份mysql,Catic构建与部署
- 时寒冰:中国房价下跌序幕刚刚拉开
- HTML及css疑问解答题前端面试题
- 递归查询,父类获取对应子类集合
- 公司价值评估-自由现金流法