There is a company that has N employees(numbered from 1 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.

InputThe first line contains a single positive integer T( T <= 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)OutputFor each test case, print the test case number (beginning with 1) in the first line and then for every inquiry, output the correspond answer per line.Sample Input

1
5
4 3
3 2
1 3
5 2
5
C 3
T 2 1
C 3
T 3 2
C 3

Sample Output

Case #1:
-1
1
2 译文:

有一个公司有N个员工(从1到N),公司里的每个员工都有一个直接的老板(除了整个公司的领导),如果你是某人的顶头上司,那个人就是你的下属,他的下属也都是你的下属。如果你不是任何人的老板,那么你就没有下属,没有直接上司的员工是整个公司的领导,这就意味着N员工组成了一棵树。
公司通常会指派一些任务给一些员工完成,当分配给某人的任务时,他/她会把它分配给所有的下属,换句话说,这个人和他/她的下属同时接受一项任务。此外,每当员工收到任务时,他/她将停止当前任务(如果他/她有)并启动新任务。
写,有助于在公司给某个员工分配任务后,计算出员工的当前任务。

题解:这道题不知道为什么归类为线段树这一类里面,感觉没什么关系,就是模拟吧,好像就过了,向上找直到最终祖先为止,

然后找时间戳最迟

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
const int MAXN=;
char s[];
int num,fa[MAXN],zhi[MAXN],now[MAXN],u,v,t,ans,mm,x,y,n,q,fzy=;
using namespace std;
void query(int x)
{
if (x==-) return;
if (zhi[x]!=-&&now[x]>mm)
{
mm=now[x];
ans=zhi[x];
}
query(fa[x]);
}
int main()
{
scanf("%d",&t);
while (t--)
{
printf("Case #%d:\n",++fzy);
memset(fa,-,sizeof(fa));
memset(zhi,-,sizeof(zhi));
memset(now,-,sizeof(now));
num=;
scanf("%d",&n);
for (int i=,v,u;i<n;i++)
{
scanf("%d%d",&v,&u);
fa[v]=u;
}
scanf("%d",&q);
for (int i=;i<=q;i++)
{
scanf("%s",&s);
if (s[]=='C')
{
scanf("%d",&x);
ans=-;mm=-;
query(x);
printf("%d\n",ans);
}
else
{
scanf("%d%d",&x,&y);
zhi[x]=y;
now[x]=++num;
}
}
}
}

的。

hdu3974 找上属的模拟的更多相关文章

  1. 【frame】找上一层

    第一种:window.parent第二种:window.top 貌似两种都行 然后找上一层iframe里面的js函数可以这么写: window.parent.functionName(param1, ...

  2. 在Windows上使用终端模拟程序连接操作Linux以及上传下载文件

    在Windows上使用终端模拟程序连接操作Linux以及上传下载文件 [很简单,就是一个工具的使用而已,放这里是做个笔记.] 刚买的云主机,或者是虚拟机里安装的Linux系统,可能会涉及到在windo ...

  3. js 上传文件模拟Form 表单

    使用FormData对象 在本文章中 创建一个FormData对象 使用HTML表单来初始化一个FormData对象 使用FormData对象发送文件 利用FormData对象,你可以使用一系列的键值 ...

  4. 上curl java 模拟http请求

    最近,我的项目要求java模拟http请求,获得dns解决 tcp处理过的信息特定的连接. java api提供urlConnection apache提供的httpClient都不能胜任该需求,二次 ...

  5. 找礼物(find)(模拟)

    找礼物(find) 时间限制: 1 Sec  内存限制: 64 MB提交: 57  解决: 4[提交][状态][讨论版] 题目描述 新 年到了,你的好友和你(共K个人)的周围满是礼物,你让你的好友先拿 ...

  6. 450A - Jzzhu and Children 找规律也能够模拟

    挺水的一道题.规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了 #include<iostream ...

  7. ueditor富文本上传图片的时候报错"未找上传数据"

    最近因为需求所以在ssh项目中使用了Ueditor富文本插件,但是在上传图片的时候总是提示“未找到上传数据”,之后百度了好久终于弄明白了.因为Ueditor在上传图片的时候会访问controller. ...

  8. 自己制作一个链表用来存储列表信息,并查找当前id信息,找上一条信息,下一条信息(信息浏览的时候方便使用)

    偶然看到某些网站在新闻详情中 ,往往是需要根据当前信息id获取到上一条信息和下一条信息的,而通常我们的做法是先获取当前信息,再获取上一条信息,再获取下一条信息,就需要发送三次查询才能够得到这些信息,一 ...

  9. 3.Docker与LXC、虚拟化技术的区别——虚拟化技术本质上是在模拟硬件,Docker底层是LXC,本质都是cgroups是在直接操作硬件

    先说和虚拟化技术的区别 难道虚拟技术就做不到吗? 不不不,虚拟技术也可以做到,但是会有一定程度的性能损失,灵活度也会下降.容器技术不是模仿硬件层次,而是 在Linux内核里使用cgroup和names ...

随机推荐

  1. python的white循环

    # _*_coding:utf-8 _*_import datetimename = 'gyf'passd = 123count =0now = datetime.datetime.now()whil ...

  2. webSocket浏览器握手不成功(解决)

    websocket与服务端握手会报握手不成功的错误解决方法: 首先是服务端首次收到请求要回报给客户端的报文要做处理多的不说,方法敬上: /// <summary> /// 打包请求连接数据 ...

  3. 实现Spring RESTful服务的SSL

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt386 本文介绍如何让基于Spring的REST服务变得SSL/TSL化. 首 ...

  4. 微软微服务eShopOnContainers示例之EventBusRabbitMq解析与实践

    eShopOnContainers eShopOnContainers是微软官方的微服务架构示例,GitHub地址https://github.com/dotnet-architecture/eSho ...

  5. html标签缺省(自带)样式大全

    html标签默认样式整理 作者:佚名  来源:互联网 时间:07-30 16:54:48 文为大家整理了html标签默认样式属性及浏览器默认样式等等,喜欢css布局的朋友们可以学下,希望对大家有所帮助 ...

  6. KVM虚拟化主机安装

    KVM虚拟化主机安装 最小化安装CentOS6.X或者CentOS7.X,RHEL6.X以上系列建议建议选择安装最小虚拟化主机 如果要安装桌面可以先选择最小化虚拟主机,再选择Gnome桌面包 安装过程 ...

  7. 四则运算GUI

    一.题目描述 我们在个人作业1中,用各种语言实现了一个命令行的四则运算小程序.进一步,本次要求把这个程序做成GUI(可以是Windows PC 上的,也可以是Mac.Linux,web,手机上的),成 ...

  8. 【Beta】 第一次Daily Scrum Meeting

    一.本次会议为第一次meeting会议 二.时间:20::0AM-20:50AM 地点:宿舍楼下 三.会议站立式照片 四.今日任务安排 成员 昨日任务 今日任务 林晓芳   对已完成的功能进行进一步测 ...

  9. 201521123033《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 参考资料: 百度脑图 XMind 2. 书面作业 作业参考文件下载 1.代码阅读:Child压缩包内源代码 1.1 com.p ...

  10. 201521123006 《Java程序设计》第4周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 1.2 使用常规方法总结其他上课内容. 本周除了继承,我们还重点学习了多态. (1)多态性在于有相同的形态,却是不同的行为或者说是不 ...