Cf739 B. ayona and a tree

Time:2022-1-8

Meaning:

A tree with some weight\(val(u)\)And edge weighted tree, point 1 is the root node. if\(v\)stay\(u\)In the subtree of,\(v\neq u\)And\(dis(u,v)\le val(v)\), it is called\(v\)cover\(u\)Control. Ask how many points each point can control.

Idea:

\(u\)Can control\(v\)Namely\(dis(u,v)\le val(v) \iff dep(v)-dep(u)\le val(v) \iff dep(u)>= dep(v)-val(v)\)

Method 1: PBDs, RB_ Tree, also called ordered_ set

For each\(u\), just find out “set s is less than or equal to”\(dep(u)\)Where s is the number of all points in the subtree of U (excluding u itself)\(dep(v)-val(v)\)A collection of values.

useorder_of_key()Strict less than\(dep(u)+1\)Number of points. To ensure that only the subtree of u is found, record the values before and after the subtree of u, and then make a difference.

Note ordered_ The elements in set cannot be repeated, so they are saved as pairs to prevent repetition. When searching, take second as 0 to ensure that it will not be calculated to be exactly equal to\(dep(u)+1\)All points less than or equal to\(dep(u)\)Point of

#include
#include
using namespace __gnu_pbds;
tree,null_type,less>,rb_tree_tag,
tree_order_statistics_node_update> S;
int t;

ll dep[N]; int ans[N];
void dfs(int u)
{
    int before = S.order_of_key({dep[u] + 1, 0});

    for(int i = h[u]; i; i = ne[i])
    {
        int v = e[i];
        dep[v] = dep[u] + w[i];

        dfs(v);
    }
    int after = S.order_of_key({dep[u] + 1, 0});
    ans[u] = after - before;

    S.insert({dep[u] - val[u], t++});
}

dfs(1);

The practice of multiplication and dichotomy needs to be supplemented

Recommended Today

The whole tutorial of docker installation and use, installation / complete command / dockerfile image production / docker container arrangement and one click installation of nginx + redis + MySQL / visualizer portal (version 2022)

官网: https://docs.docker.com/ 官网: https://www.docker.com/ docker 镜像市场: https://hub.docker.com/ 一、docker 说明 1.1、docker 核心 1、Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源,Docker 是一个 CS 架构软件。 2、Docker 是一个虚拟化轻量级linux服务器,可以解决我们在开发环境中运行配置问题 3.、Docker的主要目标是‘build ,ship and run any app,anywhere’,一次封装,到处运行 4、容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。 1.2、docker 版本问题 .Docker 从 17.03 版本之后分为 CE(Community Edition: 社区版) 和 EE(Enterprise Edition: 企业版),我们用社区版就可以了。 1.3、docker 架构( 3大核心) · 1、Images 镜像 (等于软件) · 2、Registry […]