CF1336F.Journey

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

In the wilds far beyond lies the Land of Sacredness, which can be viewed as a tree — connected undirected graph consisting of nn nodes and n−1n-1 edges. The nodes are numbered from 11 to nn.

There are mm travelers attracted by its prosperity and beauty. Thereupon, they set off their journey on this land. The ii-th traveler will travel along the shortest path from sis_i to tit_i. In doing so, they will go through all edges in the shortest path from sis_i to tit_i, which is unique in the tree.

During their journey, the travelers will acquaint themselves with the others. Some may even become friends. To be specific, the ii-th traveler and the jj-th traveler will become friends if and only if there are at least kk edges that both the ii-th traveler and the jj-th traveler will go through.

Your task is to find out the number of pairs of travelers (i,j)(i, j) satisfying the following conditions:

  • 1≤i<j≤m1 \leq i \lt j \leq m.
  • the ii-th traveler and the jj-th traveler will become friends.

在遥远的荒野之外,存在着神圣之地,该地可被视作一棵树——一个由 nn 个节点和 n−1n-1 条边构成的连通无向图。节点编号为 11 到 nn。

有 mm 位旅行者被其繁荣与美丽所吸引,因此启程踏上这片土地的旅程。第 ii 位旅行者将沿从 sis_i 到 tit_i 的最短路径行进。在此过程中,他们将遍历从 sis_i 到 tit_i 的最短路径上的所有边;由于该图为树,此最短路径是唯一的。

在旅途中,旅行者们会彼此相识,其中一些人甚至会成为朋友。具体而言,当且仅当第 ii 位旅行者与第 jj 位旅行者共同经过至少 kk 条边时,二者将成为朋友。

你的任务是求出满足以下条件的旅行者对 (i,j)(i, j) 的数量:

  • 1≤i<j≤m1 \leq i \lt j \leq m;
  • 第 ii 位旅行者与第 jj 位旅行者将成为朋友。

输入格式

The first line contains three integers nn, mm and kk (2≤n,m≤1.5⋅1052 \le n, m \le 1.5 \cdot 10^5, 1≤k≤n1\le k\le n).

Each of the next n−1n-1 lines contains two integers uu and vv (1≤u,v≤n1 \le u,v \le n), denoting there is an edge between uu and vv.

The ii-th line of the next mm lines contains two integers sis_i and tit_i (1≤si,ti≤n1\le s_i,t_i\le n, si≠tis_i \neq t_i), denoting the starting point and the destination of ii-th traveler.

It is guaranteed that the given edges form a tree.

第一行包含三个整数 nn、mm 和 kk(2≤n,m≤1.5⋅1052 \le n, m \le 1.5 \cdot 10^5,1≤k≤n1\le k\le n)。

接下来的 n−1n-1 行中,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u,v \le n),表示 uu 与 vv 之间存在一条边。

接下来的 mm 行中,第 ii 行包含两个整数 sis_i 和 tit_i(1≤si,ti≤n1\le s_i,t_i\le n,si≠tis_i \neq t_i),表示第 ii 位旅行者的起点和终点。

保证所给的边构成一棵树。

输出格式

The only line contains a single integer — the number of pairs of travelers satisfying the given conditions.

唯一的一行包含一个整数——满足给定条件的旅行者对的数量。

输入输出样例

  • 输入#1

    8 4 1
    1 7
    1 2
    2 5
    4 6
    6 3
    6 2
    6 8
    7 8
    3 8
    2 6
    4 1

    输出#1

    4
  • 输入#2

    10 4 2
    3 10
    9 3
    4 9
    4 6
    8 2
    1 7
    2 1
    4 5
    6 7
    7 1
    8 7
    9 2
    10 3

    输出#2

    1
  • 输入#3

    13 8 3
    7 6
    9 11
    5 6
    11 3
    9 7
    2 12
    4 3
    1 2
    5 8
    6 13
    5 10
    3 1
    10 4
    10 11
    8 11
    4 9
    2 5
    3 5
    7 3
    8 10

    输出#3

    14

说明/提示

In the first example there are 44 pairs satisfying the given requirements: (1,2)(1,2), (1,3)(1,3), (1,4)(1,4), (3,4)(3,4).

  • The 11-st traveler and the 22-nd traveler both go through the edge 6−86-8.
  • The 11-st traveler and the 33-rd traveler both go through the edge 2−62-6.
  • The 11-st traveler and the 44-th traveler both go through the edge 1−21-2 and 2−62-6.
  • The 33-rd traveler and the 44-th traveler both go through the edge 2−62-6.

在第一个样例中,共有 44 对旅行者满足题目要求:(1,2)(1,2)、(1,3)(1,3)、(1,4)(1,4)、(3,4)(3,4)。

  • 第 11 位旅行者与第 22 位旅行者均经过边 6-86\text{-}8。
  • 第 11 位旅行者与第 33 位旅行者均经过边 2-62\text{-}6。
  • 第 11 位旅行者与第 44 位旅行者均经过边 1-21\text{-}2 和 2-62\text{-}6。
  • 第 33 位旅行者与第 44 位旅行者均经过边 2-62\text{-}6。

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

首页