| SMU ICPC Selection Contest 2026 |
|---|
| Закончено |
Alice initially has a weighted undirected tree $$$T$$$ of $$$n$$$ nodes and $$$n-1$$$ edges. Each edge has a positive integer weight.
Alice wants to design a route so that she can walk for as long as possible, but she does not want to walk forever. To do so, she chooses a direction for every edge of the tree. In other words, for each undirected edge $$$(u,v)$$$, she replaces it with exactly one of the directed edges $$$u\rightarrow v$$$ or $$$v\rightarrow u$$$, preserving its weight $$$w_{uv}$$$. This produces a directed graph $$$T'$$$.
After constructing $$$T'$$$, Alice chooses a starting vertex $$$r$$$ ($$$1\leq r\leq n$$$), and performs the following walk:
Over all possible choices of edge directions and the starting vertex $$$r$$$, help Alice maximize the expected total distance she walks, modulo $$$10^9 + 7$$$.
It can be shown that the answer can always be written as a fraction $$$\frac{P}{Q}$$$, where $$$Q \not\equiv 0 \pmod{10^9+7}$$$. Therefore, output the value $$$$$$ P\cdot Q^{-1} \text{ mod }(10^9 + 7) $$$$$$
The first line of the input contains an integer $$$t$$$ ($$$1\leq t \leq 10^3$$$), the number of test cases. For each test case,
For each test case, output a single integer on a line, denoting the maximum expected total distance she walks, modulo $$$10^9+7$$$. Note that the answer should be maximized before taking modulo $$$10^9 + 7$$$.
192 1 37 9 58 7 57 3 13 4 14 5 35 6 23 2 3
12
There is $$$1$$$ test case. One possible edge orientation is shown in the figure below.
Illustration of Sample Test Case. Visualization created using CSAcademy's graph editor. When Alice starts from $$$r = 6$$$, she is forced to traverse $$$6\rightarrow 5 \rightarrow 4 \rightarrow 3$$$, contributing $$$2+3+1= 6$$$ to her expected distance.
From node $$$3$$$, she chooses node $$$2$$$ or node $$$7$$$ with probability $$$\frac{1}{2}$$$ each.
Therefore, the expected total distance is $$$$$$ 6+\frac{1}{2}\cdot 6 + \frac{1}{2}\cdot 6 = 12 $$$$$$ which can be shown to be the maximum expected total distance of her walk.
| Название |
|---|


