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. 简述C/C++调用lua中实现的自定义函数

    1.首先说下目的,为什么要这么做 ? 正式项目中,希望主程序尽量不做修改,于是使用C/C++完成功能的主干(即不需要经常变动的部分)用lua这类轻量级的解释性语言实现一些存在不确定性的功能逻辑:所以, ...

  2. Informatica学习:1、安装介质的获取与安装

    本文目标: 为方便学习Informatica工具,在个人电脑上部署Informatica Powercenter. 所用系统:win7 64位. Informatica安装包括服务器端.客户端安装两个 ...

  3. myeclipse eclipse创建maven web项目时 index.jsp报错

    第一种办法 解决办法: ---------------------------------------------------------------------------------------- ...

  4. sql in 和 exist的区别

    详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp41 select * from A where id in(select ...

  5. 图片懒加载Demo

    相关知识: [js获取元素位置+元素大小]全面总结

  6. VHDL学习记录

    VHDL全名Very-High-Speed Integrated Circuit Hardware Description Language ,是一种标准硬件描述语言.下面通过60进制计数器来分析VH ...

  7. 游戏平台代表--PS4【推荐】

    目前市上专业的游戏主机三足鼎立,分别是任天堂的wii,微软的xbox,已经索尼的PlayStation系列,这其中的老大当然是索尼PS4啦,因为即使美国佬也是优选ps4而不是自家的Xbox.小编历经千 ...

  8. Python 异常处理

    Python 异常处理 python提供了两个非常重要的功能来处理python程序在运行中出现的异常和错误.你可以使用该功能来调试python程序. 异常处理: 本站Python教程会具体介绍. 断言 ...

  9. Adobe Flash Player 因过期而遭遇阻止怎么办

    百度搜索"adobe flash player ppapi "并找到搜索结果中包含www.adobe.com的网址进行在线下载安装即可搞定这个问题[注意要对应你电脑系统中的浏览器, ...

  10. 当今游戏大作share的特性大盘点

    极品游戏制作时的考虑要素大盘点 不知不觉入坑Steam已近4年,虽然说Steam的毒性让很多人走向一条不归路,但是想我这样即使"中毒"还是很快乐很感恩的.那么本期文章就谈谈我对其中 ...