CF1517F.Reunion

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn volunteers of the 2050 Conference can be represented by a tree (a connected undirected graph with nn vertices and n−1n-1 edges). The nn vertices of the tree corresponds to the nn volunteers and are numbered by 1,2,…,n1,2,\ldots, n.

We define the distance between two volunteers ii and jj, dis(i,j)(i,j) as the number of edges on the shortest path from vertex ii to vertex jj on the tree. dis(i,j)=0(i,j)=0 whenever i=ji=j.

Some of the volunteers can attend the on-site reunion while others cannot. If for some volunteer xx and nonnegative integer rr, all volunteers whose distance to xx is no more than rr can attend the on-site reunion, a forum with radius rr 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 12\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-1. When all volunteers can attend, the level is defined as nn.

据报道,2050大会将于4月23日至25日在杭州云栖小镇举行,活动包括主题论坛、晨跑、露营等。

2050大会的 nn 名志愿者之间的关系可用一棵树(即一个含 nn 个顶点和 n−1n-1 条边的连通无向图)来表示。该树的 nn 个顶点对应 nn 名志愿者,编号为 1,2,…,n1,2,\ldots,n。

我们定义两名志愿者 ii 和 jj 之间的距离 dis(i,j)\text{dis}(i,j) 为树上从顶点 ii 到顶点 jj 的最短路径所含的边数。当 i=ji=j 时,dis(i,j)=0\text{dis}(i,j)=0。

部分志愿者可参加线下聚会,其余则不能。若对某名志愿者 xx 及某个非负整数 rr,所有到 xx 的距离不超过 rr 的志愿者均能参加线下聚会,则可举办一个半径为 rr 的论坛。线下聚会的等级定义为所有可能举办的论坛中最大的半径值。

假设每名志愿者独立地以概率 12\frac{1}{2} 参加线下聚会。输出线下聚会等级的期望值。当无人能参加时,等级定义为 −1-1;当所有志愿者均能参加时,等级定义为 nn。

输入格式

The first line contains a single integer nn (2≤n≤3002\le n\le 300) denoting the number of volunteers.

Each of the next n−1n-1 lines contains two integers aa and bb denoting an edge between vertex aa and vertex bb.

第一行包含一个整数 nn(2≤n≤3002\le n\le 300),表示志愿者的数量。

接下来的 n−1n-1 行每行包含两个整数 aa 和 bb,表示顶点 aa 与顶点 bb 之间的一条边。

输出格式

Output the expected level modulo 998 244 353998\,244\,353.

Formally, let M=998 244 353M = 998\,244\,353. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output such an integer xx that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

输出期望等级对 998 244 353998\,244\,353 取模的结果。

形式化地,令 M=998 244 353M = 998\,244\,353。可以证明答案可表示为一个既约分数 pq\frac{p}{q},其中 pp 和 qq 均为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出满足 p⋅q−1 mod Mp \cdot q^{-1} \bmod M 的整数。换言之,请输出满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入输出样例

  • 输入#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. yesyes means the volunteer can attend the on-site reunion and nono 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 3+1+1+(−1)23=12\frac{3+1+1+(-1)}{2^3}=\frac{1}{2}.

对于第一个例子,下表展示了所有可能的结果。“yes”表示志愿者可以参加线下聚会,“no”表示他无法参加。

123levelyesyesyes3yesyesno1yesnoyes0yesnono0noyesyes1noyesno0nonoyes0nonono−1\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}

期望等级为 3+1+1+(−1)23=12\frac{3+1+1+(-1)}{2^3}=\frac{1}{2}。

输入解题思路,AI测评打分。不知道怎么写?

首页