CF293E.Close Vertices

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You've got a weighted tree, consisting of n vertices. Each edge has a non-negative weight. The length of the path between any two vertices of the tree is the number of edges in the path. The weight of the path is the total weight of all edges it contains.

Two vertices are close if there exists a path of length at most l between them and a path of weight at most w between them. Count the number of pairs of vertices v, u (v < u), such that vertices v and u are close.

你有一棵含 $ n $ 个顶点的带权树,每条边具有非负权重。任意两个顶点之间路径的长度定义为该路径所含边的数量;路径的权重定义为该路径上所有边的权重之和。

若两个顶点之间存在一条长度至多为 $ l $ 的路径,且同时存在一条权重至多为 $ w $ 的路径,则称这两个顶点是接近的(close)。
请计算满足 $ v < u $ 的顶点对 $ (v, u) $ 的数量,使得顶点 $ v $ 和 $ u $ 是接近的。

输入格式

The first line contains three integers n, l and w (1 ≤ n ≤ 105, 1 ≤ l ≤ n, 0 ≤ w ≤ 109). The next n - 1 lines contain the descriptions of the tree edges. The i-th line contains two integers p__i, w__i (1 ≤ p__i < (i + 1), 0 ≤ w__i ≤ 104), that mean that the i-th edge connects vertex (i + 1) and p__i and has weight w__i.

Consider the tree vertices indexed from 1 to n in some way.

第一行包含三个整数 nn、ll 和 ww(1 ≤ n ≤ 1051 ≤ n ≤ 10^5,1 ≤ l ≤ n1 ≤ l ≤ n,0 ≤ w ≤ 1090 ≤ w ≤ 10^9)。接下来的 n − 1n - 1 行描述树的边。第 ii 行包含两个整数 pip_i、wiw_i(1 ≤ pi < (i + 1)1 ≤ p_i < (i + 1),0 ≤ wi ≤ 1040 ≤ w_i ≤ 10^4),表示第 ii 条边连接顶点 (i + 1)(i + 1) 与 pip_i,且其权重为 wiw_i。

考虑将树的顶点以某种方式编号为 11 到 nn。

输出格式

Print a single integer — the number of close pairs.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输出一个整数——紧密对的数量。

请注意,在 C++ 中读取或写入 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。

输入输出样例

  • 输入#1

    4 4 6
    1 3
    1 4
    1 3

    输出#1

    4
  • 输入#2

    6 2 17
    1 3
    2 5
    2 13
    1 6
    5 9

    输出#2

    9

输入解题思路,AI测评打分。不知道怎么写?

首页