F - Assign the task

本文介绍了一个关于员工任务分配的问题及解决方案。在一个公司员工组成的树形结构中,当任务被分配给某个员工时,该员工及其所有下属将停止当前任务并开始新任务。文章提供了一种通过查找集的方法来查询特定员工当前的任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

并查集!

先确定每个人的老板关系!在结构体中增加一个time,表示被分配任务的时间!最后查找的时候,都是查找到company的老板,查找途中,遇到更新time迟的就更新ans!可以保证最后答案一定是最后布置的!

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include<iomanip>
using namespace std;
typedef long long ll;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define pi acos(-1)
#define N 50005

struct
{
	int task;
	int time;
}  po[N];


int t,n,u,v,x,y,m;
int pre[N];
int main()
{
	scanf("%d",&t);
	int casee=1;
	while(t--)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			po[i].task=-1;
			po[i].time=0;
		}
		for(int i=1;i<=n;i++)
		  pre[i]=i;
		for(int i=1;i<=n-1;i++)
		{
			scanf("%d%d",&u,&v);
			pre[u]=v;
		}
		scanf("%d",&m);
		char s[5];
		int t=1;
		printf("Case #%d:\n",casee++);
		while(m--)
		{
			int time=0;
			int ans=-1;
			scanf("%s",s);
			if(s[0]=='C')
			{
				scanf("%d",&x);
				while(pre[x]!=x)
				{
					if(po[x].time>time)
					{
						time=po[x].time;
						ans=po[x].task;
					}
					x=pre[x];
				}
				if(po[x].time>time) ans=po[x].task;
				printf("%d\n",ans);
			}
			else
			{
				scanf("%d%d",&x,&y);
				po[x].task=y;
				po[x].time=t++;
			}
		}
	}
	return 0;
}



bitbake --help usage: bitbake [-s] [-e] [-g] [-u UI] [--version] [-h] [-f] [-c CMD] [-C INVALIDATE_STAMP] [--runall RUNALL] [--runonly RUNONLY] [--no-setscene] [--skip-setscene] [--setscene-only] [-n] [-p] [-k] [-P] [-S SIGNATURE_HANDLER] [--revisions-changed] [-b BUILDFILE] [-D] [-l DEBUG_DOMAINS] [-v] [-q] [-w WRITEEVENTLOG] [-B BIND] [-T SERVER_TIMEOUT] [--remote-server REMOTE_SERVER] [-m] [--token XMLRPCTOKEN] [--observe-only] [--status-only] [--server-only] [-r PREFILE] [-R POSTFILE] [-I EXTRA_ASSUME_PROVIDED] [recipename/target [recipename/target ...]] It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which will provide the layer, BBFILES and other configuration information. General options: recipename/target Execute the specified task (default is 'build') for these target recipes (.bb files). -s, --show-versions Show current and preferred versions of all recipes. -e, --environment Show the global or per-recipe environment complete with information about where variables were set/changed. -g, --graphviz Save dependency tree information for the specified targets in the dot syntax. -u UI, --ui UI The user interface to use (knotty, ncurses, taskexp, taskexp_ncurses or teamcity - default knotty). --version Show programs version and exit. -h, --help Show this help message and exit. Task control options: -f, --force Force the specified targets/task to run (invalidating any existing stamp file). -c CMD, --cmd CMD Specify the task to execute. The exact options available depend on the metadata. Some examples might be 'compile' or 'populate_sysroot' or 'listtasks' may give a list of the tasks available. -C INVALIDATE_STAMP, --clear-stamp INVALIDATE_STAMP Invalidate the stamp for the specified task such as 'compile' and then run the default task for the specified target(s). --runall RUNALL Run the specified task for any recipe in the taskgraph of the specified target (even if it wouldn't otherwise have run). --runonly RUNONLY Run only the specified task within the taskgraph of the specified targets (and any task dependencies those tasks may have). --no-setscene Do not run any setscene tasks. sstate will be ignored and everything needed, built. --skip-setscene Skip setscene tasks if they would be executed. Tasks previously restored from sstate will be kept, unlike --no-setscene. --setscene-only Only run setscene tasks, don't run any real tasks. Execution control options: -n, --dry-run Don't execute, just go through the motions. -p, --parse-only Quit after parsing the BB recipes. -k, --continue Continue as much as possible after an error. While the target that failed and anything depending on it cannot be built, as much as possible will be built before stopping. -P, --profile Profile the command and save reports. -S SIGNATURE_HANDLER, --dump-signatures SIGNATURE_HANDLER Dump out the signature construction information, with no task execution. The SIGNATURE_HANDLER parameter is passed to the handler. Two common values are none and printdiff but the handler may define more/less. none means only dump the signature, printdiff means recursively compare the dumped signature with the most recent one in a local build or sstate cache (can be used to find out why tasks re-run when that is not expected) --revisions-changed Set the exit code depending on whether upstream floating revisions have changed or not. -b BUILDFILE, --buildfile BUILDFILE Execute tasks from a specific .bb recipe directly. WARNING: Does not handle any dependencies from other recipes. Logging/output control options: -D, --debug Increase the debug level. You can specify this more than once. -D sets the debug level to 1, where only bb.debug(1, ...) messages are printed to stdout; -DD sets the debug level to 2, where both bb.debug(1, ...) and bb.debug(2, ...) messages are printed; etc. Without -D, no debug messages are printed. Note that -D only affects output to stdout. All debug messages are written to ${T}/log.do_taskname, regardless of the debug level. -l DEBUG_DOMAINS, --log-domains DEBUG_DOMAINS Show debug logging for the specified logging domains. -v, --verbose Enable tracing of shell tasks (with 'set -x'). Also print bb.note(...) messages to stdout (in addition to writing them to ${T}/log.do_<task>). -q, --quiet Output less log message data to the terminal. You can specify this more than once. -w WRITEEVENTLOG, --write-log WRITEEVENTLOG Writes the event log of the build to a bitbake event json file. Use '' (empty string) to assign the name automatically. Server options: -B BIND, --bind BIND The name/address for the bitbake xmlrpc server to bind to. -T SERVER_TIMEOUT, --idle-timeout SERVER_TIMEOUT Set timeout to unload bitbake server due to inactivity, set to -1 means no unload, default: Environment variable BB_SERVER_TIMEOUT. --remote-server REMOTE_SERVER Connect to the specified server. -m, --kill-server Terminate any running bitbake server. --token XMLRPCTOKEN Specify the connection token to be used when connecting to a remote server. --observe-only Connect to a server as an observing-only client. --status-only Check the status of the remote bitbake server. --server-only Run bitbake without a UI, only starting a server (cooker) process. Configuration options: -r PREFILE, --read PREFILE Read the specified file before bitbake.conf. -R POSTFILE, --postread POSTFILE Read the specified file after bitbake.conf. -I EXTRA_ASSUME_PROVIDED, --ignore-deps EXTRA_ASSUME_PROVIDED Assume these dependencies don't exist and are already provided (equivalent to ASSUME_PROVIDED). Useful to make dependency graphs more appealing.
07-29
if name == ‘main’: # manager = Manager() # kill_now = manager.Value(“i”, 0) # semaphore = manager.BoundedSemaphore(2) # # 优雅下线 # running_tasks = manager.list([]) # killer = GracefulOffline(kill_now, running_tasks) # obs_path_queue = TaskBaseInfoBlockedQueue(maxsize=OBS_QUEUE_LEN) # file_path_queue = DownloadEventPkgBlockedQueue(maxsize=FILE_QUEUE_LEN) # upload_msgs_queue = UploadMsgInfoBlockedQueue(maxsize=FINISH_QUEUE_LEN) # kafka_msgs_queue = KafkaMsgsBlockedQueue(maxsize=KAFKA_QUEUE_LEN) # # 开启常驻进程 # stages = run_state() # init_task = InitTaskWorker(output_q=obs_path_queue) # task = None # while True: # try: # if killer.kill_now.get(): # logger.info(“offline begin, exit the main loop”) # break # task = init_task.get_data() # if task: # element = init_task.parse(task) # killer.running_tasks.append((task.ids, task.data_name, task.assign_time)) # # 这里的timeout和定时任务中check_light_alive的时长一致 # init_task.put_res(element, timeout=constants.TIME_OUT_SEC) # except queue.Full: # logger.error(f"obs_path_queue full") # time.sleep(10) # except Exception as err: # if task is not None and (task.ids, task.data_name, task.assign_time) in killer.running_tasks: # killer.running_tasks.remove((task.ids, task.data_name, task.assign_time)) # logger.error(f"Exception occurred in MainThread: {err.class.name}, {traceback.format_exc()}") # time.sleep(10) # sys.exit(0) manager = Manager() kill_now = manager.Value(“i”, 0) semaphore = manager.BoundedSemaphore(2) # 优雅下线 running_tasks = manager.list([]) killer = GracefulOffline(kill_now, running_tasks) obs_path_queue = TaskBaseInfoBlockedQueue(maxsize=OBS_QUEUE_LEN) file_path_queue = DownloadEventPkgBlockedQueue(maxsize=FILE_QUEUE_LEN) upload_msgs_queue = UploadMsgInfoBlockedQueue(maxsize=FINISH_QUEUE_LEN) kafka_msgs_queue = KafkaMsgsBlockedQueue(maxsize=KAFKA_QUEUE_LEN) # 开启常驻进程 stages = run_state() init_task = InitTaskWorker(output_q=obs_path_queue) task = ParseTask() task.msg = json.dumps([ “{"dataName": "13001_ddi-application-735823413343428882-0-A", "featureType": 1, "groupId": 312, "projectId": 10000, "eventId": 13001, "eventType": 0, "uploadStartTime": 1753251021000, "uploadEndTime": 1753251069120, "uploadCostTime": 48120, "fileSize": 94207887, "verifyCode": null, "moveStartTime": 1753251069271, "moveEndTime": 1753251069271, "decodeStartTime": 1753251069271, "decodeEndTime": 1753251072380, "status": 2, "errorMsg": null, "filePath": "/ddi-sbeta2-20220210/lite/13001_ddi-application-735823413343428882-0-A.tar", "eventTime": 1753250964000, "transactionNumber": "0b3c8433-4e42-4998-9cda-0a73caafe817", "oceanFileId": "1300120250723060924a173318537b66d2eaf66494207887", "oceanFileName": "C_A_13001_2025_07_23_06_09_24_0.bin", "mdcId": "99554920", "userId": "huawei", "mid": "2dc1ee5f35104ad6aa00e1443710f61e", "vid": "15b98468f1644fe8a38a8cc547fd96e3", "vehicleName": "X4-PPV-EVR-065", "mdcSn": "HX24B0016943", "groupName": "bjev_stelato\u8f66\u4f01x4_evr\u8f66\u578b\u5546\u7528\u7ec4", "mdcUsage": 1, "calibrationStatus": "002", "calibrationFileName": "41063a086b105ce9c67ec825cc9289209a5e20895bcd85c9.tar.gz", "calibrationObsPath": "/ddi/calibration/ba3a1c95a95d405f8a385106f45be9b0/41063a086b105ce9c67ec825cc9289209a5e20895bcd85c9.tar.gz", "saveMode": "1000", "saveModeKey": "C_13001_2025_07_23_06_09_24", "uuid": "-1", "vehicleAssociated": 1, "isSecurity": 0, "privacyId": "99554920", "checkKafkaStatus": 0, "dataPull": 0, "commercialDelivered": 0, "license": 0, "moveKafkaSendTime": "1753251069120", "oemModel": "x4_evr", "oemBrand": "bjev_stelato", "sensorVersion": "3.74", "eventSource": "10", "processType": "4", "packageExtraData": "{\"mdcType\":\"MDC620Pro\",\"dieId\":\"d2eaf6640180ea1d198ab66574a5090a7e003e5b\",\"boardType\":\"MDC620ProDebug2212\",\"vehicleClusterList\":[\"beiqi\"]}", "basicAuth": "1", "parentDataName": "13001_ddi-application-735823413343428882-0-A", "eventCategory": "1"}”]) element = init_task.parse(task) killer.running_tasks.append((task.ids, task.data_name, task.assign_time)) init_task.put_res(element, timeout=constants.TIME_OUT_SEC) time.sleep(100)这段代码在window解释器下正常在Linux解释器上出现SIGSEGV这个是什么问题TaskBaseInfoBlockedQueue继承multiprocessing中queueif name == ‘main’: # manager = Manager() # kill_now = manager.Value(“i”, 0) # semaphore = manager.BoundedSemaphore(2) # # 优雅下线 # running_tasks = manager.list([]) # killer = GracefulOffline(kill_now, running_tasks) # obs_path_queue = TaskBaseInfoBlockedQueue(maxsize=OBS_QUEUE_LEN) # file_path_queue = DownloadEventPkgBlockedQueue(maxsize=FILE_QUEUE_LEN) # upload_msgs_queue = UploadMsgInfoBlockedQueue(maxsize=FINISH_QUEUE_LEN) # kafka_msgs_queue = KafkaMsgsBlockedQueue(maxsize=KAFKA_QUEUE_LEN) # # 开启常驻进程 # stages = run_state() # init_task = InitTaskWorker(output_q=obs_path_queue) # task = None # while True: # try: # if killer.kill_now.get(): # logger.info(“offline begin, exit the main loop”) # break # task = init_task.get_data() # if task: # element = init_task.parse(task) # killer.running_tasks.append((task.ids, task.data_name, task.assign_time)) # # 这里的timeout和定时任务中check_light_alive的时长一致 # init_task.put_res(element, timeout=constants.TIME_OUT_SEC) # except queue.Full: # logger.error(f"obs_path_queue full") # time.sleep(10) # except Exception as err: # if task is not None and (task.ids, task.data_name, task.assign_time) in killer.running_tasks: # killer.running_tasks.remove((task.ids, task.data_name, task.assign_time)) # logger.error(f"Exception occurred in MainThread: {err.class.name}, {traceback.format_exc()}") # time.sleep(10) # sys.exit(0) manager = Manager() kill_now = manager.Value(“i”, 0) semaphore = manager.BoundedSemaphore(2) # 优雅下线 running_tasks = manager.list([]) killer = GracefulOffline(kill_now, running_tasks) obs_path_queue = TaskBaseInfoBlockedQueue(maxsize=OBS_QUEUE_LEN) file_path_queue = DownloadEventPkgBlockedQueue(maxsize=FILE_QUEUE_LEN) upload_msgs_queue = UploadMsgInfoBlockedQueue(maxsize=FINISH_QUEUE_LEN) kafka_msgs_queue = KafkaMsgsBlockedQueue(maxsize=KAFKA_QUEUE_LEN) # 开启常驻进程 stages = run_state() init_task = InitTaskWorker(output_q=obs_path_queue) task = ParseTask() task.msg = json.dumps([ “{"dataName": "13001_ddi-application-735823413343428882-0-A", "featureType": 1, "groupId": 312, "projectId": 10000, "eventId": 13001, "eventType": 0, "uploadStartTime": 1753251021000, "uploadEndTime": 1753251069120, "uploadCostTime": 48120, "fileSize": 94207887, "verifyCode": null, "moveStartTime": 1753251069271, "moveEndTime": 1753251069271, "decodeStartTime": 1753251069271, "decodeEndTime": 1753251072380, "status": 2, "errorMsg": null, "filePath": "/ddi-sbeta2-20220210/lite/13001_ddi-application-735823413343428882-0-A.tar", "eventTime": 1753250964000, "transactionNumber": "0b3c8433-4e42-4998-9cda-0a73caafe817", "oceanFileId": "1300120250723060924a173318537b66d2eaf66494207887", "oceanFileName": "C_A_13001_2025_07_23_06_09_24_0.bin", "mdcId": "99554920", "userId": "huawei", "mid": "2dc1ee5f35104ad6aa00e1443710f61e", "vid": "15b98468f1644fe8a38a8cc547fd96e3", "vehicleName": "X4-PPV-EVR-065", "mdcSn": "HX24B0016943", "groupName": "bjev_stelato\u8f66\u4f01x4_evr\u8f66\u578b\u5546\u7528\u7ec4", "mdcUsage": 1, "calibrationStatus": "002", "calibrationFileName": "41063a086b105ce9c67ec825cc9289209a5e20895bcd85c9.tar.gz", "calibrationObsPath": "/ddi/calibration/ba3a1c95a95d405f8a385106f45be9b0/41063a086b105ce9c67ec825cc9289209a5e20895bcd85c9.tar.gz", "saveMode": "1000", "saveModeKey": "C_13001_2025_07_23_06_09_24", "uuid": "-1", "vehicleAssociated": 1, "isSecurity": 0, "privacyId": "99554920", "checkKafkaStatus": 0, "dataPull": 0, "commercialDelivered": 0, "license": 0, "moveKafkaSendTime": "1753251069120", "oemModel": "x4_evr", "oemBrand": "bjev_stelato", "sensorVersion": "3.74", "eventSource": "10", "processType": "4", "packageExtraData": "{\"mdcType\":\"MDC620Pro\",\"dieId\":\"d2eaf6640180ea1d198ab66574a5090a7e003e5b\",\"boardType\":\"MDC620ProDebug2212\",\"vehicleClusterList\":[\"beiqi\"]}", "basicAuth": "1", "parentDataName": "13001_ddi-application-735823413343428882-0-A", "eventCategory": "1"}”]) element = init_task.parse(task) killer.running_tasks.append((task.ids, task.data_name, task.assign_time)) init_task.put_res(element, timeout=constants.TIME_OUT_SEC) time.sleep(100)这段代码在window解释器下正常在Linux解释器上出现SIGSEGV这个是什么问题TaskBaseInfoBlockedQueue继承multiprocessing中queue进程的启动方式是forkserver
最新发布
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值