HDU 3974 assign the task (and query the set adaptation)

Source: Internet
Author: User

Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3974

 

This question is like this:

Give you n, meaning there are n people

Then the next n rows are the relationships between these people.

Two digits indicate that the latter is the boss of the former.

Then I will give you another M, which means there are m cases below

When you encounter C, you need to output the task that the manager of the number following current C is currently doing.

If you encounter T, for example, T 2 1, you need to assign Task 1 to the Manager 2. In addition, all his subordinates need to change to this task immediately.

 

Therefore, when C occurs, it is possible to ask the manager about the current task.

The processing method is to delay the mark.

Write down the task of the last parent manager who changed the task

 

The AC code is as follows (for more information, please forgive me. If you see something similar, please do not spray it. I apologize here ):

#include <stdio.h>#include <iostream>using namespace std;const int MAX = 50010;struct NODE{int task,count;};NODE p[MAX];int parent[MAX];void init(){memset(parent,-1,sizeof(parent));}int main(){int ncases,n,u,v,m,x,task;char s[5];scanf("%d",&ncases);int ind=1;while(ncases--){scanf("%d",&n);init();int i;for(i=0;i<n-1;i++){scanf("%d%d",&u,&v);parent[u]=v;}for(i=1;i<=n;i++){p[i].task=-1;p[i].count=-1;}scanf("%d",&m);printf("Case #%d:\n",ind++);int count=0;while(m--){scanf("%s",s);if(s[0]=='T'){scanf("%d%d",&x,&task);p[x].task=task;p[x].count=++count;}else{scanf("%d",&x);task=p[x].task;int count=p[x].count;while(x!=-1){if(p[x].count>count){task=p[x].task;count=p[x].count;}x=parent[x];}printf("%d\n",task);}}}return 0;}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.