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表示查询某员工的任务.本题的难度在于建树,一开始百思不得 ...
随机推荐
- modelformset
class StudyRecordDeialView(View): def get(self, request, class_record_id): class_record_obj = models ...
- Postman 没有走hosts文件
问题: 在Windows10系统中,从官方下载Postman安装并登录后,创建一个请求并执行.但这个请求并没有走hosts文件中定义的192.168.33.10主机,而是走到了线上的主机. 分析: 通 ...
- 09GNU C语言程序编译
1. C 语言程序概述 GNU gcc 对 ISO 标准 C89 描述的 C 语言进行了一些扩展,其中一些扩展部分已经包括进 IOS C99 标准中.本节给出了内核中经常用到的一些 gcc 扩展语 ...
- 第一课:PHP 文件是什么?
PHP 文件是什么? PHP 文件可包含文本.HTML.JavaScript代码和 PHP 代码 PHP 代码在服务器上执行,结果以纯 HTML 形式返回给浏览器 PHP 文件的默认文件扩展名是 &q ...
- python 类的使用
目录 类的继承 类的派生 类的组合 菱形继承问题 多态与多态性 dataclass的使用 类的继承 什么是继承,在生活中,子承父业,父亲和儿子就是继承的关系 在python中,父类和子类(派生类),父 ...
- Python中的列表(1)
1.什么是列表? 列表是由一组按特定顺序排列的元素组成. 2.如何表示? 在Python中用方括号([ ])来表示列表.栗子如下: contries = ['China','England','Fra ...
- LeetCode(282) Peeking Iterator
题目 Given an Iterator class interface with methods: next() and hasNext(), design and implement a Peek ...
- 1036: [ZJOI2008]树的统计Count(树链剖分)
1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 19830 Solved: 8067[Submit ...
- 05-python进阶-简单监控程序开发
#!/usr/bin/env python #coding:utf-8 ''' 监控监控程序 ''' import json import urllib import inspect import o ...
- 移动端click时间、touch事件、tap事件详解
一.click 和 tap 比较 两者都会在点击时触发,但是在手机WEB端,click会有 200~300 ms,所以请用tap代替click作为点击事件. singleTap和doubleTap 分 ...