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 ...
最新文章
- csu 1554: SG Value 思维题
- html简单网页代码表白_表白网页代码,不会代码也可以操作,告别单身
- SAP:HANA为高性能数据分析保驾护航
- IAAS、PAAS与SAAS
- ORA-01925:maximum of 80 enabled roles exceeded
- Matplotlib从文件绘图时Y轴坐标不正确
- 计算1!+2!+...+n!
- python 把函数作为参数 ---高阶函数
- 实现第一个JDBC程序(详细)
- 将科学计数法的数值转化为字符
- CSS美化超链接样式
- 注册界面模板HTML+CSS
- RTKLIB专题学习(十二)—支持的信号ID/观测类型及读取优先级
- 射频中经常是用50欧姆作为阻抗匹配的标准的原因
- 虚拟机无法连接虚拟设备sata0:1
- OCR财务报表识别方案应用
- python知到答案_Python语言应用_知到网课答案
- SSH框架相关准备与入门学习
- android文字闪动效果
- 教你正确使用文字识别软件ABBYY的转换格式功能
热门文章
- Java中类方法可以继承吗_在Java语言中,类方法(静态方法)可以被继承,但是不能被( )。_学小易找答案...
- 大唐仙侠传java,大唐仙侠传官网版,大唐仙侠传手游官网版预约 v1.0-手游汇
- 炒菜机器人康名牌_机器人帮炒菜,九阳、美的产品各有何本领?
- “智慧交通”转型升级+创新发展策略
- telnet命令及测试网络端口的几种方法
- linux 单引号和双引号区别
- 优盘数据恢复怎么做?3个方法分享!
- Java--The import *** cannot be resolved问题解决方案
- CANoe-发送CAN消息的几种方式
- mac睡眠状态下远程唤醒_如何控制Mac自动进入睡眠状态的时间