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. java对象与json对象之间的转换

    jar包:import net.sf.json.JSONObject; 1.解析json字符串 将json字符串转换为json对象,然后再解析json对象:.JSONObjectjsonObject ...

  2. Ubuntu16.04+CUDA8.0+CUNN5.1+caffe+tensorflow+Theano

    title: Ubuntu 16.04+CUDA8.0+CUNN5.1+caffe+tensorflow+Theano categories: 深度学习 tags: [深度学习框架搭建] --- 前言 ...

  3. selenium之handle学习 多窗口、句柄

    我们拿松勤软件测试的网站做例子: 直接获取all_handle这个list数据里面第二个handle的值:all_handle[1] # coding:utf-8 from selenium impo ...

  4. HTML中document.getElementById()方法的操作

    转自:http://blog.csdn.net/pyffcwj/article/details/7240232/ obj = document.getElementById("cc" ...

  5. Python输入输出练习,运算练习,turtle初步练习

    Hello World! 简单交互(交互式,文件式)教材P19 radius=25 area=3.1415*radius*radius print(area) print('{:.2f}'.forma ...

  6. ES6块级作用域

    块级作用域的优点 避免变量冲突,比如程序中加载了多个第三方库的时候,如果没有妥善地将内部私有函数或变量隐藏起来,就很容易引发变量冲突: 可以方便的进行模块管理: 利于内存回收:(块级作用域里声明的变量 ...

  7. (三)、LNMP的搭建,并制作rpm包

    中小型规模网站集群架构:yum仓库搭建 : 矮哥linux运维群:93324526 编译的三条命令的规则 ./configure 就是在本地创建了一个Makefile文件 (也就是指定一下各种配置参数 ...

  8. 对#ifndef的理解

    由于对#ifndef的用法不太理解,在询问了老师#ifndef的含义以及查找资料后,对#ifndef总结了以下几点: <1> #ifndef是宏定义的一种,是三种预处理功能(宏定义,文件包 ...

  9. 【Alpha阶段】第七次scrum meeting

    一.会议照片 二.会议内容 姓名 学号 负责模块 昨日任务 今日任务 杨爱清 099 界面设计和交互功能 [完成]设计界面 交互功能连接并优化 杨立鑫 100 数据库搭建和其他 [完成]将数据库与其他 ...

  10. 团队作业4——第一次项目冲刺(Alpha版本)日志集合处

    Day 1: http://www.cnblogs.com/TeamOf/p/6754373.html Day 2: http://www.cnblogs.com/TeamOf/p/6754410.h ...