#P17424. [ICPC 2018 Xuzhou R] Rikka with Intersections of Paths

    ID: 16830 Type: RemoteJudge 10000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>2018线段树最近公共祖先 LCA树链剖分组合数学差分ICPC

[ICPC 2018 Xuzhou R] Rikka with Intersections of Paths

题目描述

Rikka has a tree TT with nn vertices numbered from 11 to nn.

Meanwhile, Rikka has marked mm simple paths in TT, the ii-th of which is between the vertices xix_i and yiy_i, where some of them could be the same path.

Now, Rikka wants to know in how many different strategies she can select kk paths from the marked paths such that those selected paths share at least one common vertex.

输入格式

The input contains several test cases, and the first line contains a single integer TT (1≤T≤2001 \le T \le 200), the number of test cases.

For each test case, the first line contains three integers nn (1≤n≤3×1051 \le n \le 3 \times 10^5), the size of the tree TT, mm (2≤m≤3×1052 \le m \le 3 \times 10^5), the number of marked paths, and kk (2≤k≤m2 \le k \le m).

The following (n−1)(n - 1) lines describe the tree TT. Each of them contains two integers uu and vv (1≤u,v≤n1 \le u, v \le n, u≠vu \ne v), representing an edge between the vertices uu and vv.

The following mm lines describe all marked simple paths in the tree. The ii-th of them contains two integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i, y_i \le n).

The input guarantees that the sum of nn and the sum of mm in all test cases are at most 2×1062 \times 10^6 respectively.

输出格式

For each test case, output a single line with a single integer, the number of different strategies meeting the requirement modulo (109+7)(10^9 + 7).

1
3 6 2
1 2
1 3
1 1
2 2
3 3
1 2
1 3
2 3
10