Assign the task HDU
来源:互联网 发布:网吧软件管理系统 编辑:程序博客网 时间:2024/05/22 17:32
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.
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.
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)
1 5 4 3 3 2 1 3 5 2 5 C 3 T 2 1 C 3 T 3 2 C 3
Case #1:-1 1 2
#include<bits/stdc++.h>using namespace std;const int M=5e4+10;int tree[4*M],lazy[4*M],s[M],e[M],cnt,pre[M],cont;bool vis[M];struct aa{ int u,v,next;} edge[M];void add(int u,int v){ edge[cnt].u=u; edge[cnt].v=v; edge[cnt].next=pre[u]; pre[u]=cnt++;}void buildsegment(int t){ s[t]=++cont; for(int i=pre[t]; i!=-1; i=edge[i].next) { buildsegment(edge[i].v); } e[t]=cont;}void creat(int now,int l,int r){ lazy[now]=tree[now]=-1; if(l!=r) { int mid=(r+l)/2; creat(now*2+1,l,mid); creat(now*2+2,mid+1,r); }}void falldown(int now){ if(lazy[now]>=0) { tree[now*2+1]=tree[now*2+2]=lazy[now*2+1]=lazy[now*2+2]=lazy[now]; lazy[now]=-1; }}void update(int now,int l,int r,int al,int ar,int k){ if(al>r||ar<l) return; if(al<=l&&ar>=r) { tree[now]=lazy[now]=k; return ; } int mid=(r+l)/2; falldown(now); update(now*2+1,l,mid,al,ar,k); update(now*2+2,mid+1,r,al,ar,k);}int query(int now,int l,int r,int s){ int mid=(l+r)/2; if(l==r) { return tree[now]; } falldown(now); if(s<=mid) { query(now*2+1,l,mid,s); } else { query(now*2+2,mid+1,r,s); }}int main(){ int t; scanf("%d",&t); int kase=1; while(t--) { printf("Case #%d:\n",kase++); int n; scanf("%d",&n); cnt=0,cont=-1; for(int i=0; i<=n; i++) { pre[i]=-1,vis[i]=0; } for(int i=0; i<n-1; i++) { int u,v; scanf("%d%d",&u,&v); add(v,u); vis[u]=1; } creat(0,0,n-1); for(int i=1; i<=n; i++) { if(!vis[i]) { buildsegment(i); break; } } int m; scanf("%d",&m); while(m--) { char temp[4]; scanf("%s",temp); if(temp[0]=='C') { int a; scanf("%d",&a); printf("%d\n",query(0,0,n-1,s[a])); } else { int a,b; scanf("%d%d",&a,&b); // printf("*** T %d %d***\n",s[a],e[a]); update(0,0,n-1,s[a],e[a],b); } } }}
阅读全文
0 0
- Assign the task HDU
- Assign the task HDU
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- HDU 3974 Assign the task
- HDU 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- Assign the task(hdu 3974)
- HDU 3974 Assign the task (线段树)
- HDU 3974 Assign the task(线段树)
- hdu 3974 Assign the task (线段树)
- HDU 3974——Assign the task
- HDOJ Assign the task
- hdu3974 Assign the task
- hdu3974----Assign the task
- HDU3974-Assign the task
- 【Nova】nova-network网络模型之flat网络
- <#list List/Map/Array[] as Object> Freemarker
- 记录:JavaMail小实例
- LoadRunner 关联和集合点、检查点
- BigDL安装配置流程
- Assign the task HDU
- 多旋翼无人机翻滚360度(flip实现方法)
- equal与==的区别
- 帆软报表js给某个单元格添加背景色
- python模块之feedparser学习使用
- 用龙芯1c库在RT-Thread下实现外部中断(GPIO中断、按键中断)
- [LeetCode] 565. Array Nesting
- synchronized和lock的用法区别
- String s=new String("abc")创建了2个对象的原因