Assign the task dfs序+线段树

2023 ICRA《Visual Language Maps for Robot Navigation》阅读笔记 视觉语言导航可以使用预先训练的现有的视觉语言模型来将图像与对象目标的自然语言描述相匹配,但它与绘制环境的过程仍然脱节,缺乏经典几何地图的空间精度。为了解决这个问题,我们提出了VLMaps,这是一种空间地图表示,它将预训练的视觉语言特征与物理世界的3D重建直接融合在一起。VLMaps可以使用标准探索方法从机器人上的视频馈送中自主构建,并在没有额外标记数据的情况下实现地图的自然语言索引。具体来说,当与大型语言模型(LLM)相结合时,VLMaps可以用于。 阅读详情

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.

Input

The 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)

Output

For 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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <cmath>
#include <vector>
using namespace std;
const int NUM=50005;
const int inf=0x3f3f3f3f;
struct point
{
    int l,r,w,f;
}tree[NUM*4];
int in[NUM],out[NUM];
vector<int> vec[NUM];
int time;
void dfs(int a) //dfs序
{
    in[a]=++time;   //在新序列中in[a]对应a点,区间【in[a],out[a]】对应以a为根的子树
    for(int i=0;i<vec[a].size();i++)  
        dfs(vec[a][i]);
    out[a]=time;
} //在dfs序完成后就可以不管之前的树了,用线段树对新序列进行维护就行了
int LL,RR,val;
void build(int k,int LL,int RR)
{
    tree[k].l=LL,tree[k].r=RR;
    tree[k].f=-1,tree[k].w=-1;
    if(tree[k].l==tree[k].r){
        return;
    }
    int bet=(tree[k].l+tree[k].r)/2;
    build(k*2,LL,bet);
    build(k*2+1,bet+1,RR);
}
void down(int k)
{
    tree[k*2].f=tree[k*2+1].f=tree[k].f;
    tree[k*2].w=tree[k*2].f;
    tree[k*2+1].w=tree[k*2+1].f;
    tree[k].f=-1;
}
void change(int k)
{
    if(LL<=tree[k].l&&RR>=tree[k].r){
        tree[k].w=val;
        tree[k].f=val;
        return;
    }
    if(tree[k].f!=-1) down(k);
    int bet=(tree[k].l+tree[k].r)/2;
    if(LL<=bet) change(k*2);
    if(RR>bet) change(k*2+1);
}
int ans;
void ask(int k,int point)
{
    if(tree[k].l==tree[k].r){
        ans=tree[k].w;
        return;
    }
    if(tree[k].f!=-1) down(k);
    int bet=(tree[k].l+tree[k].r)/2;
    if(point<=bet) ask(k*2,point);
    else ask(k*2+1,point);
}
int fp[NUM];
char ss[2];
int main()
{
    int t,cnt=1;
    scanf("%d",&t);
    while(t--){
        memset(fp,0,sizeof(fp));
        time=0;
        int n;
        scanf("%d",&n);
        build(1,1,n);
        for(int i=1;i<=n;i++)
            vec[i].clear();
        int a,b;
        for(int i=0;i<n-1;i++){
            scanf("%d %d",&a,&b);
            fp[a]++;
            vec[b].push_back(a);
        }
        int treepre;
        for(int i=1;i<=n;i++){ //查找树的根节点
            if(fp[i]==0){
                treepre=i;
                break;
            }
        }
        dfs(treepre);
        int m;
        scanf("%d",&m);
        printf("Case #%d:\n",cnt++);
        for(int i=0;i<m;i++){
            scanf("%s",ss);
            if(ss[0]=='C'){
                scanf("%d",&a);
                ask(1,in[a]);
                printf("%d\n",ans);
            }
            else{
                scanf("%d %d",&a,&b);
                LL=in[a],RR=out[a],val=b;
                change(1);
            }
        }
    }
    return 0;
}

 

MFC实现键盘钩子(附完整源码) 阅读详情

相关推荐

用友u8服务器优化,用友U8erp软件运行的性能优化方案图文教程

今天一定要给大家分享一下用友U8erp软件运行的性能优化方案图文教程,以下方案来自用友软件官方维护工程师反馈在在处理客户问题的时候,有一类问题较为挠头,就是诸如用友U8服务器效率低下的问题。比如用友U8运行慢,卡住等,我们暂先不提用友U8软件代码、脚本层面本身的性能提升问题,我们只是基于现有用友U8软件版本,在客户现有环境下排查用友U8软件运行的性能瓶颈,并采取一定的技术手段进行性能调校。本文将推...

weixin_39882870的博客 5306

HDU 3974 Assign the task(简单线段树)

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 th...

weixin_33739523的博客 291

【Linux】实际项目应该如何完成?--安防监控系统项目的总结

到目前为止我也做个5、6个嵌入式项目,但以往都是从零开始自己做,也就是毫无计划,想到那里做那里,有想法就会去实现,就这样导致我碰到了很多坑,也消耗了我许多时间,当然,不是说这样不好,因为在其中我也得到了一个很好的锻炼与练习,但是这不适用于在工作中去这样做。...

修成真的博客 6729

Assign the task(dfs序+线段树)

题目传送门 Assign the task 题目大意 给你一棵树,共n个结点,每个结点具有一个颜色,可以对结点进行染色和查询 共n-1条边,分N-1行分别包含两个整数u和v,表示v是u的父节点 然后有m次操作 若为染色操作则输入“T x k” 若为查询操作则输入“C x” 思路 首先可以用dfs序将无根树区间化,即可以求出每个节点的管辖区间 然后就是区间修改,单点查询即可,维护每个点的值即可 AC Code #include<bits/stdc++.h> using namespace std;

Kuricip的博客 394

Halcon 3D视觉实战:5步将线激光高度数据转为可分析的深度图与点云

本文详细介绍了如何利用Halcon平台将线激光高度数据转换为深度图与点云的5步实战方法。通过具体代码示例和工业检测案例(如锂电池胶水测量),帮助工程师高效处理3D视觉数据,实现从原始数据到三维可视化的完整技术链路。

weixin_29039773的博客 361

MES系统领料申请、出库、确认到料各环节的处理

在WMS和MES系统协同的车间管理中,核心分工原则为:MES负责生产需求发起(领料申请)和结果确认(到料验收),WMS执行库存管理和物流作业。具体流程为:1)MES根据生产需求生成领料单推送至WMS;2)WMS完成拣货出库并调度AGV配送;3)车间在MES确认到料后解锁生产工序。系统边界严格限定:MES不参与库存/库位管理,WMS不干预生产决策。特殊场景(紧急补料、缺料异常等)通过标准化接口流程处理,确保生产与物流高效协同的同时保持账实一致。

做有价值的事,积累有价值的笔记! 586

Assign the task (线段树)

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

SunMoonVocano的博客 443

PyTorch生成式人工智能(1)——神经网络与模型训练过程详解

在本节中,我们介绍了传统机器学习与人工神经网络间的差异,并了解了如何在实现前向传播之前连接网络的各个层,以计算与网络当前权重对应的损失值;实现了反向传播以优化权重达到最小化损失值的目标。并实现了网络的所有关键组成——前向传播、激活函数、损失函数、链式法则和梯度下降,从零开始构建并训练了一个简单的神经网络。

盼小辉丶的博客 1万+

[好题][树的遍历][线段树]Assign the task HDU3974

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

Cloth的博客 233

【数字孪生工业应用实战】第2篇:数字孪生系统架构设计与技术选型——从“作秀”到“实干”的骨架构建

本文系统剖析了数字孪生系统从“作秀”到“实干”的架构设计关键。针对多数项目在POC转生产时因架构混乱、选型盲目而失败的问题,深入阐述了四层分层架构(感知层、传输层、模型层、应用层)的设计原则,重点解析了感知层的异构适配与边缘预处理、传输层的异步解耦与多模式通信等工程细节。结合OPC UA、MQTT、EdgeX Foundry等主流技术选型对比,以及汽车焊装车间边缘智能网关的实战代码,提供了从零搭建微型孪生系统的完整指导。旨在帮助工程师建立清晰的选型决策逻辑,构建稳定、可演进的数字孪生“骨架”。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 267

部署模型:Libtorch使用笔记【Pytorch的C++版本】【把用Pytorch训练好的模型打包保存为.pt格式,使用Libtorch去加载.pt格式模型,在C++工程中去用就好了】

A : Libtorch是pytorch的C++版本,现在的很多大型项目都是用C++写的,想使用训练好的模型,需要通过caffe等方式去集成,比较麻烦。这里pytorch官方提出了Libtorch,我们就可以把pytorch训练好的模型,打包起来,直接在C++工程中去用就好了,相比较caffe等,非常方便!虽然对于许多需要动态性和易迭代性的场景来说,Python是一种合适且首选的语言,但在同样的情况下,Python的这些特性恰恰是不利的。生产环境是一个需要低延迟和有严格部署要求的领域,一般选择C++。

u013250861的博客 2950

并查集--Assign the task

Assign the task 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...

duganlx的博客 545

芒果YOLO11改进106:检测头篇DynamicHead动态检测头:基于DynamicHead,二次原创提出SATNeXt模块,提出全新的动态DynamicSatDetect

检测头篇DynamicHead动态检测头:基于DynamicHead,二次原创提出SATNeXt模块,提出全新的动态DynamicSatDetect

包括YOLOv5、YOLOv7、YOLOv8等模型改进 773

Assign the task //线段树+dfs序

链接点这里 题意: 一个公司n个人,每个人都有上司,除了最大的boss,并且一个人上司的上司仍是他的上司,现在给某个人安排一项任务,等同于给他和他的下属安排这项命令,现在要给某个人赋予任务,或查询某个人现在的任务。 解析: 这道题的线段树的单点查询与区间更新很好维护,主要是怎样找对应人在线段树中的位置,利用dfs序即可解决。详细内容看代码。 #include <iostream> #i...

wqq的博客 189

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

[Assign the task][dfs序+线段树]

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): 7144Accepted Submissi...

aiyuneng5167的博客 170

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

Assign the task (DFS序 + 线段树)

Assign the task [Link](Problem - 3974 (dingbacode.com)) 题意 现有一棵树,有以下操作: 节点x及其所有子孙颜色都变更为k。 要求你回答节点x的颜色。 初始所有点都没有染色。 题解 ​ **DFS序:**一棵树按照深度优先遍历时,对于每个结点,在刚进入递归后以及即将回溯前各记录一次该点的编号,最后产生的长度为2n的结点序列称为树的DFS序。 **性质:**每个结点x的编号在序列中恰好出现两次,设这两次出现的位置为L[x], R[x],则闭区间[L

a12377978的博客 159

Assign the task HDU - 3974 dfs序 +线段树

一、内容 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...

Tizzi的博客 1068

(线段树/dfs序)Assign the task

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 so...

weixin_40588429的博客 279

Hdu 3974——Assign the task dfs序+线段树

题目: link. 题意: 公司里有一堆人,然后对于每个人(除了公司老板)每个人都有上属和下属,他们恰好构成一棵树,每当把任务分给某个人时,若他有下属,则他的所有子树全部做这个任务,对于每次查询输出某个节点正在做什么任务。 输入有2种操作: 1、C x 输入x这个人在做的任务编号 如果没工作输出-1 2、T x y 让x和x的下属做编号为y的工作 思路: 先跑一边dfs序,每个节点记录一个in和out表示时间戳,对于每个人p,in[p]到out[p]这段区间就是p的下属,dfs序完了之后用线段树维护每个人的

HHeyanjie的博客 198

HDU 3974(Assign the task)线段树维护dfs序

题目: 在这里啊 题意: 一个公司有一个老板及许多员工 ,除老板外,每个员工都有自己的领导,然而每次分配工作之后,如果自己的领导得到了工作则自己也会去干相同的工作。 每次询问要问一个一人在干什么工作。 思路: 最简单可以想到的就是单点维护单点查询,这个我帮你们试过了,妥妥超时, 所以我们要优化一下,要区间更新,单点查询,因为每个人都有自己的领导,所以从公司的老板开始做深搜,这样子之后统计一下每个点...

laaahu的博客 467

Assign the task(线段树 + DFS序)

题目链接:Assign the task(HDU - 3974) 题目大意: 现有一棵树,有以下操作: 1 . 节点x及其所有子孙颜色都变更为k。 2 . 要求你回答节点x的颜色。 解题思路: 对于题目要求,我们需要维护的是一棵树,我们知道树是一种树形结构而非线性结构,因此操作起来比较复杂。那么我们是否可以将树形结构转换成线性结构那,答案是肯定的。DFS序就是一种很好的方法。 DFS序是将树形结构转化为线性结构的一种方式,用dfs从根节点遍历一遍这棵树,进入到x节点时有一个in时间戳,递归退出时有一个out

Try_harder的博客 378

HDU - 3974 Assign the task DFS序建线段树

训练摸鱼发现好久没写博客了,下个月去区域赛了,有点小慌,水个博客压压惊。 不想贴题目,简单说下题意就是有一群员工具有上下级关系,体现出来就是一颗多叉树,子节点是父亲的下属这样子。然后现在安排工作,更新一个员工的工作序号的时候需要同时把下属的工作序号一起完成更新。 dfs序+线段树区间处理一下就水过了 线段树是基本操作。dfs序就是因为是一颗多叉树,那么对于树dfs遍历节点的出入得到一个序列,...

limyoonaya的博客 197

J - Assign the task(线段树+dfs序)

题目链接 通过dfs序 将 上下级关系树 转换成线性结构, (转换成线性结构 便于 上级 和下级一起更新) 然后构建线段树, 进行修改查询。 #include<bits/stdc++.h> using namespace std; const int maxn = 5e5+50; int dfs[maxn]; // dfs序数组 vector<int>G[maxn];//...

T.J的博客 238

hdu3974-Assign the task(dfs序建线段树)

title: hdu3974-Assign the task(dfs序建线段树) date: 2019-05-28 15:08:01 categories: ACM tags: [ACM,算法] 今天做线段树的题碰到一个需要dfs序转化成建线段树,挺有意义的一道题 我的个人博客:https://www.kimiye.xyz 题目描述 There is a company that has ...

Flyyy‘s blog 460

【HDU3974]Assign the task dfs序或欧拉序+线段树

description 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 o...

weixin_39637396的博客 298

hdu 3974 Assign the task(dfs序上线段树)

Problem Description 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 immed...

weixin_30825581的博客 116
上一篇: Tunnel Warfare 线段树区间合并
下一篇: HDU 1828 扫描线求周长
Chter0
博客等级 码龄8年 13粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值