A14186 | Reunion
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It is reported that the 2050 Conference will be held in Yunqi Town in Hangzhou from April 23 to 25, including theme forums, morning jogging, camping and so on.
The relationship between the $n$ volunteers of the 2050 Conference can be represented by a tree (a connected undirected graph with $n$ vertices and $n-1$ edges). The $n$ vertices of the tree corresponds to the $n$ volunteers and are numbered by $1,2,\ldots, n$ .
We define the distance between two volunteers $i$ and $j$ , dis $(i,j)$ as the number of edges on the shortest path from vertex $i$ to vertex $j$ on the tree. dis $(i,j)=0$ whenever $i=j$ .
Some of the volunteers can attend the on-site reunion while others cannot. If for some volunteer $x$ and nonnegative integer $r$ , all volunteers whose distance to $x$ is no more than $r$ can attend the on-site reunion, a forum with radius $r$ can take place. The level of the on-site reunion is defined as the maximum possible radius of any forum that can take place.
Assume that each volunteer can attend the on-site reunion with probability $\frac{1}{2}$ and these events are independent. Output the expected level of the on-site reunion. When no volunteer can attend, the level is defined as $-1$ . When all volunteers can attend, the level is defined as $n$ .
The relationship between the $n$ volunteers of the 2050 Conference can be represented by a tree (a connected undirected graph with $n$ vertices and $n-1$ edges). The $n$ vertices of the tree corresponds to the $n$ volunteers and are numbered by $1,2,\ldots, n$ .
We define the distance between two volunteers $i$ and $j$ , dis $(i,j)$ as the number of edges on the shortest path from vertex $i$ to vertex $j$ on the tree. dis $(i,j)=0$ whenever $i=j$ .
Some of the volunteers can attend the on-site reunion while others cannot. If for some volunteer $x$ and nonnegative integer $r$ , all volunteers whose distance to $x$ is no more than $r$ can attend the on-site reunion, a forum with radius $r$ can take place. The level of the on-site reunion is defined as the maximum possible radius of any forum that can take place.
Assume that each volunteer can attend the on-site reunion with probability $\frac{1}{2}$ and these events are independent. Output the expected level of the on-site reunion. When no volunteer can attend, the level is defined as $-1$ . When all volunteers can attend, the level is defined as $n$ .
输入格式
The first line contains a single integer $n$ ( $2\le n\le 300$ ) denoting the number of volunteers.
Each of the next $n-1$ lines contains two integers $a$ and $b$ denoting an edge between vertex $a$ and vertex $b$ .
Each of the next $n-1$ lines contains two integers $a$ and $b$ denoting an edge between vertex $a$ and vertex $b$ .
输出格式
Output the expected level modulo $998\,244\,353$ .
Formally, let $M = 998\,244\,353$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
Formally, let $M = 998\,244\,353$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
输入输出样例
输入 #1
3 1 2 2 3
输出 #1
499122177
输入 #2
5 1 2 2 3 3 4 3 5
输出 #2
249561089
输入 #3
10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
输出 #3
821796866
For the first example, the following table shows all possible outcomes. $yes$ means the volunteer can attend the on-site reunion and $no$ means he cannot attend. $$$$\begin{array}{cccc} 1 & 2 & 3 & level\\ yes & yes & yes & 3\\ yes & yes & no & 1\\ yes & no & yes & 0\\ yes & no & no & 0\\ no & yes & yes & 1\\ no & yes & no & 0\\ no & no & yes & 0\\ no & no & no & -1\\ \end{array} $$ The expected level is $\\frac{3+1+1+(-1)}{2^3}=\\frac{1}{2}$$$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted