#abc244f. F - Shortest Good Path
F - Shortest Good Path
Score : points
问题描述
你将得到一个包含 个顶点和 条边的简单连通无向图。(若图中没有重边且没有自环,则称该图为简单图。) 对于 ,第 条边连接顶点 和顶点 。
如果满足以下两个条件,那么序列 被称为长度为 的路径:
- 对于所有 ,有 。
- 对于所有 ,顶点 和顶点 直接由一条边相连。
空序列被视为长度为 的路径。
令 为长度为 的字符串,仅由 和 构成。对于字符串 ,若路径 满足以下条件,则称其为相对于 的好路径:
- 对于所有 ,满足:
- 如果 ,则 中含有偶数个 。
- 如果 ,则 中含有奇数个 。
共有 种可能的 (换句话说,存在 个由 和 组成、长度为 的字符串)。找出所有这些 中“最短好路径的长度”之和。
在本题的约束条件下,可以证明:对于任意由 和 组成的长度为 的字符串 ,都至少存在一条相对于 的好路径。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a simple connected undirected graph with vertices and edges. (A graph is said to be simple if it has no multi-edges and no self-loops.)
For , the -th edge connects Vertex and Vertex .
A sequence is said to be a path of length if both of the following two conditions are satisfied:
- For all , it holds that .
- For all , Vertex and Vertex are directly connected by an edge.
An empty sequence is regarded as a path of length .
Let be a string of length consisting of and . A path is said to be a good path with respect to if the following conditions are satisfied:
- For all , it holds that:
- if , then has even number of 's.
- if , then has odd number of 's.
There are possible (in other words, there are strings of length consisting of and ). Find the sum of "the length of the shortest good path with respect to " over all those .
Under the Constraints of this problem, it can be proved that, for any string of length consisting of and , there is at least one good path with respect to .
Constraints
- The given graph is simple and connected.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 2
1 2
2 3
Sample Output 1
14
- For , the empty sequence is the shortest good path with respect to , whose length is .
- For , is the shortest good path with respect to , whose length is .
- For , is the shortest good path with respect to , whose length is .
- For , is the shortest good path with respect to , whose length is .
- For , is the shortest good path with respect to , whose length is .
- For , is the shortest good path with respect to , whose length is .
- For , is the shortest good path with respect to , whose length is .
- For , is the shortest good path with respect to , whose length is .
Therefore, the sought answer is .
Sample Input 2
5 5
4 2
2 3
1 3
2 1
1 5
Sample Output 2
108
update @ 2024/3/10 10:30:09