• CF708C Centroids


    Description

    Tree is a connected acyclic graph. Suppose you are given a tree consisting of nn vertices. The vertex of this tree is called centroid if the size of each connected component that appears if this vertex is removed from the tree doesn't exceed $frac{n}{2}$.

    You are given a tree of size $n$ and can perform no more than one edge replacement. Edge replacement is the operation of removing one edge from the tree (without deleting incident vertices) and inserting one new edge (without adding new vertices) in such a way that the graph remains a tree. For each vertex you have to determine if it's possible to make it centroid by performing no more than one edge replacement.

    给定一颗树,你有一次将树改造的机会,改造的意思是删去一条边,再加入一条边,保证改造后还是一棵树。

    请问有多少点可以通过改造,成为这颗树的重心?(如果以某个点为根,每个子树的大小都不大于$frac{n}{2}$,则称某个点为重心)

    Solution

    当以一棵树的根为其重心时,其所有点的子树大小都$le frac{n}{2}$,因为根节点的所有子树大小都$le frac{n}{2}$

    以树的重心为根,对于点$u$,树中$n-siz_{u}$的部分若可以取出一个最大的大小$le frac{n}{2}$的部分,设其大小为$f_u$,则当$n-siz_u-f_u le frac{n}{2}$时,点$u$可以被改造为重心

    具体改造方法为将取下来的部分接到$u$上

    $f_u$的值可能为:

    1. $n-siz_u$
    2. 其兄弟节点中$siz$值最大的
    3. $f_{fa_u}$

    三遍DFS,第一遍找原树重心,第二遍维护$siz$和$siz$的最大值和次大值,第三遍求$f$

    Centroids
  • 相关阅读:
    __attribute__((noreturn))的用法
    selenium定位元素的方法
    zzz
    go语言的第一个helloworld
    mac eclipse 创建Java 工程
    Jmeter:图形界面压力测试工具
    使用 HAProxy, PHP, Redis 和 MySQL 轻松构建每周上亿请求Web站点
    从Log4j迁移到LogBack的理由
    SLF4J和Logback日志框架详解
    security with restful
  • 原文地址:https://www.cnblogs.com/JDFZ-ZZ/p/13555525.html
Copyright © 2020-2023  润新知