CF1770E.Koxia and Tree
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Imi has an undirected tree with n vertices where edges are numbered from 1 to n−1 . The i -th edge connects vertices ui and vi . There are also k butterflies on the tree. Initially, the i -th butterfly is on vertex ai . All values of a are pairwise distinct.
Koxia plays a game as follows:
- For i=1,2,…,n−1 , Koxia set the direction of the i -th edge as ui→vi or vi→ui with equal probability.
- For i=1,2,…,n−1 , if a butterfly is on the initial vertex of i -th edge and there is no butterfly on the terminal vertex, then this butterfly flies to the terminal vertex. Note that operations are sequentially in order of 1,2,…,n−1 instead of simultaneously.
- Koxia chooses two butterflies from the k butterflies with equal probability from all possible 2k(k−1) ways to select two butterflies, then she takes the distance † between the two chosen vertices as her score.
Now, Koxia wants you to find the expected value of her score, modulo 998244353‡ .
† The distance between two vertices on a tree is the number of edges on the (unique) simple path between them.
‡ Formally, let M=998244353 . It can be shown that the answer can be expressed as an irreducible fraction qp , where p and q are integers and q≡0(modM) . Output the integer equal to p⋅q−1modM . In other words, output such an integer x that 0≤x<M and x⋅q≡p(modM) .
输入格式
The first line contains two integers n , k ( 2≤k≤n≤3⋅105 ) — the size of the tree and the number of butterflies.
The second line contains k integers a1,a2,…,ak ( 1≤ai≤n ) — the initial position of butterflies. It's guaranteed that all positions are distinct.
The i -th line in following n−1 lines contains two integers ui , vi ( 1≤ui,vi≤n , ui=vi ) — the vertices the i -th edge connects.
It is guaranteed that the given edges form a tree.
输出格式
Output a single integer — the expected value of Koxia's score, modulo 998244353 .
输入输出样例
输入#1
3 2 1 3 1 2 2 3
输出#1
748683266
输入#2
5 3 3 4 5 1 2 1 3 2 4 2 5
输出#2
831870296
说明/提示
In the first test case, the tree is shown below. Vertices containing butterflies are noted as bold.
There are only 2 butterflies so the choice of butterflies is fixed. Let's consider the following 4 cases:
- Edges are 1→2 and 2→3 : butterfly on vertex 1 moves to vertex 2 , but butterfly on vertex 3 doesn't move. The distance between vertices 2 and 3 is 1 .
- Edges are 1→2 and 3→2 : butterfly on vertex 1 moves to vertex 2 , but butterfly on vertex 3 can't move to vertex 2 because it's occupied. The distance between vertices 2 and 3 is 1 .
- Edges are 2→1 and 2→3 : butterflies on both vertex 1 and vertex 3 don't move. The distance between vertices 1 and 3 is 2 .
- Edges are 2→1 and 3→2 : butterfly on vertex 1 doesn't move, but butterfly on vertex 3 move to vertex 2 . The distance between vertices 1 and 2 is 1 .
Therefore, the expected value of Koxia's score is 41+1+2+1=45 , which is 748683266 after modulo 998244353 .
In the second test case, the tree is shown below. Vertices containing butterflies are noted as bold. The expected value of Koxia's score is 611 , which is 831870296 after modulo 998244353 .