题目链接:https://vjudge.net/problem/HDU-3974 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…
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 subordinat…
描述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 subordin…
http://acm.hdu.edu.cn/showproblem.php?pid=3974 Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7144    Accepted Submission(s): 2708 Problem Description There is a company that h…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 给你T组数据,n个节点,n-1对关系,右边的是左边的父节点,所有的值初始化为-1,然后给你q个操作: 有两种操作: 操作一:T X Y ,将以X为根的子树上的所有节点都变成Y. 操作二:C X,查询第X号点是多少? 没想到是线段树做,就算想到了也想不到用dfs序做... 例子中给你了这样的树: 2 /     \ 3       5 /    \ 4      1 DFS一遍转化成DFS序:2…
题目大意:公司里有一些员工及对应的上级,给出一些员工的关系,分配给某员工任务后,其和其所有下属都会进行这项任务.输入T表示分配新的任务, 输入C表示查询某员工的任务.本题的难度在于建树,一开始百思不得其解,后来看了lx大大的博客后才明白,用递归建立了各个员工之间的关系,Start[x] 表示x员工为Boss的起点,End[x]表示x员工为Boss的终点.之后对这样的整体线段进行赋值即可. #include <stdio.h> #include <algorithm> #includ…
Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 636    Accepted Submission(s): 322 Problem Description There is a company that has N employees(numbered from 1 to N),every employ…
Snacks Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2165    Accepted Submission(s): 513 Problem Description 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充,零食机的价值v会时常发…
题意: 一个公司里面每个员工都有一个顶头上司,一旦给某个员工分配任务后,这个员工以及该员工的所有下属都在做该任务. 有若干操作,分配给员工任务以及查询该员工正在执行的任务. 题解: 典型的更新字树的操作,用时间戳来区分子树,然后用线段树做区间的修改和查询.简单介绍一下时间戳(按照dfs的顺寻把一个点第一次遍历的时间点 以及最后一次也就是第二次遍历到的时间点保存下来 具体看下图 会发现一个点的第一次和第二次的时间包含了同样标记的子节点第一次遍历的时间) 序列话之后,用线段树维护查询就好咯,注意一下…
题意: 一个公司有n个员工,每个员工都有一个上司,一个人下属的下属也是这个人的下属,因此可将他们的关系看成一棵树, 然后给定两种操作,C操作是查询当前员工的工作,T操作是将y工作分配给x员工,当一个人得到y工作时,他的 员工也会得到这个工作,即这个点和他的子树的工作都变成y. 链接: http://acm.hdu.edu.cn/showproblem.php?pid=3974 思路: 先一遍dfs求出该员工掌管的员工区间,每次修改时用线段树修改这个区间的员工即可,而查询时只要查询l_[x](该员…