No.1507 Road Blocked
問題文最終更新日: 2021-05-14 19:19:04
English (AI translation)
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence.
Back to the original
yukicoder contest 295
(順位表)
の他の問題:
Problem Statement
You are given a tree $G$ with $N$ vertices. The vertices are numbered with integers from $1$ to $N$, and the $i$-th edge connects vertices $u_i$ and $v_i$.
Choose $2$ distinct vertices $A,B$ and $1$ edge $E$ from $G$ uniformly at random. Find the probability that $A$ and $B$ are connected when $E$ is removed from $G$. It can be proved that this probability is a rational number, so find it $\text{mod}\ 998244353$ as described in the Notes.Notes
To output a rational number, first represent it as a fraction $\displaystyle\frac pq$, where $p,q$ are integers and $q$ must not be divisible by $998244353$ (under the constraints of this problem, such a representation is always possible). Then, output the unique integer $k$ that is at least $0$ and less than $998244353$ such that $qk\equiv p\ \left(\text{mod}\ 998244353\right)$.Constraints
Input
$N$
$u_1\ v_1$
$\vdots$
$u_{N-1}\ v_{N-1}$
Output
Output the $k$ that satisfies the condition.
Sample
Sample 1
Input
4 1 2 2 3 3 4
Output
776412275
The probability to find is $\displaystyle\frac49$. The positive integer less than $998244353$ that satisfies $\displaystyle 4\equiv 9k\ \text{mod}\ 998244353$ is $776412275$, so output this.
Sample 2
Input
2 1 2
Output
0
No matter how $A,B,E$ are chosen, $A$ and $B$ are never connected. Therefore, output $0$.
Sample 3
Input
5 4 5 2 1 5 1 1 3
Output
648858830
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
magsta