#P14666. [KenOI 2025] 游走题

    ID: 14532 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创O2优化树形 DP树论组合数学排列组合洛谷比赛

[KenOI 2025] 游走题

Description

Given a rooted tree with nn nodes, rooted at node 11. Now let's start the wander from node ss, abiding by the following rules:

  • If we have gone to uu's parent ff from uu, delete the edge (u,f)(u,f) immediately.
  • When uu has no neighbor, the wander stops.

For two plans A,BA,B, we call they are essentially different only when the sets of nodes they pass through are different. It can be proven that if plan A,BA,B are the same, the numbers of step that their token are also the same.

Compute the sum of the lengths of all essentially different walks, modulo 109+710^9+7.

Input Format

The first line contains two integers nn and ss.

The next n1n-1 lines each contains two positive integers uu and vv, representing an edge (u,v)(u,v).

Output Format

A single integer, the sum of the lengths modulo 109+710^9+7.

7 5
2 1
3 2
4 2
5 3
6 5
7 3
48

Hint

Example explanation

Consider all possible essentially different paths:

  • 5,3,2,15,3,2,1;

  • 5,3,7,3,2,15,3,7,3,2,1;

  • 5,3,7,3,2,4,2,15,3,7,3,2,4,2,1;

  • 5,3,2,4,2,15,3,2,4,2,1;

  • 5,6,5,3,2,15,6,5,3,2,1;

  • 5,6,5,3,7,3,2,15,6,5,3,7,3,2,1;

  • 5,6,5,3,2,4,2,15,6,5,3,2,4,2,1;

  • 5,6,5,3,7,3,2,4,2,15,6,5,3,7,3,2,4,2,1;

The sum is 4848.

Data Volume and Conventions

This problem is divided into subtasks. Your score in a subtask is the minimum score across all its test cases.

This problem uses subtask dependencies. You will not receive the score for a subtask unless you achieve full points on all its dependent subtasks.

Subtask nn \le Special Properties Score Dependencies
11 55 none 1010 none
22 10310^3 2525 11
33 10610^6 A 55 none
44 B 1010
55 C 2020
66 none 3030 1,2,3,4,51,2,3,4,5

Special property A: i[1,n),ui=1\forall i \in [1,n),u_i=1.
Special property B: i[1,n),ui=i,vi=i+1\forall i \in [1,n),u_i=i,v_i=i+1.
Special property C: s=1s=1.

For all of the cases, 1sn1061 \le s \le n \le 10^6.