P3565 [POI2014]HOT-Hotels

    • 508通过
    • 1.3K提交
  • 题目提供者 洛谷
  • 评测方式 云端评测
  • 标签 动态规划,动规,dp 树形动规 POI 2014 高性能
  • 难度 省选/NOI-
  • 时空限制 1000ms / 128MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 体验新版界面

    最新讨论 显示

    推荐的相关题目 显示

    题目描述

    There are $n$ towns in Byteotia, connected with only $n-1$ roads.

    Each road directly links two towns.

    All the roads have the same length and are two way.

    It is known that every town can be reached from every other town via a route consisting of one or more (direct-link) roads.

    In other words, the road network forms a tree.

    Byteasar, the king of Byteotia, wants three luxury hotels erected to attract tourists from all over the world.

    The king desires that the hotels be in different towns and at the same distance one from each other.

    Help the king out by writing a program that determines the number of possible locations of the hotel triplet in Byteotia.

    有一个树形结构,每条边的长度相同,任意两个节点可以相互到达。选3个点。两两距离相等。有多少种方案?

    输入输出格式

    输入格式:

    The first line of the standard input contains a single integer $n$ ($1\le n\le 5\ 000$), the number of towns in Byteotia.

    The towns are numbered from $1$ to $n$.

    The Byteotian road network is then described in $n-1$ lines.

    Each line contains two integers $a$ and $b$ ($1\le a\le b\le n$) , separated by a single space, that indicate there is a direct road between the towns $a$ and $b$.

    输出格式:

    The first and only line of the standard output should contain a single integer equal to the number of possible placements of the hotels.

    输入输出样例

    输入样例#1: 复制
    7
    1 2
    5 7
    2 5
    2 3
    5 6
    4 5
    
    输出样例#1: 复制
    5
    

    说明

    有一个树形结构,每条边的长度相同,任意两个节点可以相互到达。选3个点。两两距离相等。有多少种方案?

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。