hdu 3874 Assign the task
Assign the task
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2600 Accepted Submission(s):
1098
to N),every employee in the company has a immediate boss (except for the leader
of whole company).If you are the immediate boss of someone,that person is your
subordinate, and all his subordinates are your subordinates as well. If you are
nobody's boss, then you have no subordinates,the employee who has no immediate
boss is the leader of whole company.So it means the N employees form a
tree.
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.
<= 10 ), indicates the number of test cases.
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)
(beginning with 1) in the first line and then for every inquiry, output the
correspond answer per line.
5
4 3
3 2
1 3
5 2
5
C 3
T 2 1
C 3
T 3 2
C 3
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int N_MAX = +;
vector<int>G[N_MAX];
queue<int>que;
int cur_work[N_MAX];
int print[N_MAX];
int N,M; void ceng_xu(int emp,int y) {
que.push(emp);
while (!que.empty()) {
int emp = que.front();
que.pop();
cur_work[emp] = y;
for (int i = ; i < G[emp].size(); i++) {
que.push(G[emp][i]);
}
}
} int main() {
int t,k=;
scanf("%d",&t);
while (t--) {
int num = ;//用于记录print赋值的次数
k++;//测试样本数
memset(cur_work,-,sizeof(cur_work));
scanf("%d",&N);
for (int i = ; i < N - ; i++) {
int emp, boss;//下标都从1开始
scanf("%d%d",&emp,&boss);
G[boss].push_back(emp);
}
scanf("%d",&M);
for (int i = ; i < M; i++) {
char c;
scanf(" %c",&c);
if (c == 'C') {
int a;
scanf("%d",&a);
print[num++]=cur_work[a];
}
else {
int emp, y;
scanf("%d%d",&emp,&y);
ceng_xu(emp, y);
}
}
for (int i = ; i < N; i++) {
G[i].clear();
} printf("Case #%d:\n",k);
for (int i = ; i < num; i++)
printf("%d\n",print[i]);
}
return ;
}
hdu 3874 Assign the task的更多相关文章
- HDU 3974 Assign the task 并查集/图论/线段树
Assign the task Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 3974 Assign the task 暴力/线段树
题目链接: 题目 Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 3974 Assign the task(简单线段树)
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3974 Assign the task
Assign the task Problem Description There is a company that has N employees(numbered from 1 to N),ev ...
- HDU 3947 Assign the task
http://acm.hdu.edu.cn/showproblem.php?pid=3974 Problem Description There is a company that has N emp ...
- 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 (线段树+树的遍历)
Description There is a company that has N employees(numbered from 1 to N),every employee in the comp ...
- hdu 3974 Assign the task(dfs序上线段树)
Problem Description There is a company that has N employees(numbered from 1 to N),every employee in ...
- HDU 3974 Assign the task(dfs建树+线段树)
题目大意:公司里有一些员工及对应的上级,给出一些员工的关系,分配给某员工任务后,其和其所有下属都会进行这项任务.输入T表示分配新的任务, 输入C表示查询某员工的任务.本题的难度在于建树,一开始百思不得 ...
随机推荐
- C#访问数组元素
在C#中,使用索引来访问数组元素.索引必须是一个整型值. 在数组中,每一个维度的索引从0开始. 一.访问一维数组元素 int[] array = {1,2,3,4,5,6,7,8,9,10}; // ...
- Java第11次作业:什么是继承?继承的好处?什么是覆写?super()?构造代码块?子父类初始化顺序? 抽象类能用final声明吗?final关键字声明类 方法 变量以及全局常量?抽象类的构造方法?
什么是继承? 继承是以父类为基础,子类可以增加新的数据或新的功能.子类不能选择性地继承父类.这种技术使得复用以前的代码非常容易. JAVA不支持多继承,单继承使JAVA的继承关系很简单,一个类只能有一 ...
- Java第7次作业:造人类(用private封装,用static关键字自己造重载输出方法)什么是面向对象程序设计?什么是类和对象?什么是无参有参构造方法 ?什么是封装?
什么是面向对象程序设计? 我们称为OOP(Object Oriented Programming) 就是非结构化的程序设计 要使用类和对象的方法来进行编程 什么是类,什么是对象 类就是封装了属性和 ...
- .Net Core依赖注入中TryAddEnumerable 和TryAddTransient方法的区别
.Net Core依赖注入添加的每个服务,最终都会转换为一个ServiceDescriptor的实例,ServiceDescriptor包含以下属性: Lifetime:服务的生命周期(Singlet ...
- graph-basic
打算使用STL中的vector,通过邻接链表的方式存储图.这里贴基本定义,以及depth-first-search和breadth-first-search的实现代码. 其他图的算法实现,就贴在各自的 ...
- Mac中文乱码问题
在终端切换到文档所在的目录,输入下面的命令: iconv -c -f GB2312 -t UTF-8 乱码的文件名 >> 新文件的名称
- debian 7 安装vagrant
下载 vagrant_1.4.3_x86_64.deb: $ wget http://966b.http.dal05.cdn.softlayer.net/data-production/2f0b88e ...
- 主席树 - Luogu 1001 A+B problem
看着大佬们的解法我瑟瑟发抖 我用主席树写一写吧 #include<iostream> #include<iomanip> #include<cmath> #incl ...
- 缓存淘汰算法之LFU
1. LFU类 1.1. LFU 1.1.1. 原理 LFU(Least Frequently Used)算法根据数据的历史访问频率来淘汰数据,其核心思想是“如果数据过去被访问多次,那么将来被访问的频 ...
- 一个TensorFlow例子
一个TensorFlow的例子 import tensorflow as tf x = tf.constant(1.0, name='input') w = tf.Variable(0.8, name ...