#abc244f. F - Shortest Good Path

F - Shortest Good Path

Score : 500500 points

问题描述

你将得到一个包含 NN 个顶点和 MM 条边的简单连通无向图。(若图中没有重边且没有自环,则称该图为简单图。) 对于 i=1,2,,Mi = 1, 2, \ldots, M,第 ii 条边连接顶点 uiu_i 和顶点 viv_i

如果满足以下两个条件,那么序列 (A1,A2,,Ak)(A_1, A_2, \ldots, A_k) 被称为长度为 kk路径

  • 对于所有 i=1,2,,ki = 1, 2, \dots, k,有 1AiN1 \leq A_i \leq N
  • 对于所有 i=1,2,,k1i = 1, 2, \ldots, k-1,顶点 AiA_i 和顶点 Ai+1A_{i+1} 直接由一条边相连。

空序列被视为长度为 00 的路径。

S=s1s2sNS = s_1s_2\ldots s_N 为长度为 NN 的字符串,仅由 0011 构成。对于字符串 SS,若路径 A=(A1,A2,,Ak)A = (A_1, A_2, \ldots, A_k) 满足以下条件,则称其为相对于 SS好路径

  • 对于所有 i=1,2,,Ni = 1, 2, \ldots, N,满足:
    • 如果 si=0s_i = 0,则 AA 中含有偶数个 ii
    • 如果 si=1s_i = 1,则 AA 中含有奇数个 ii

共有 2N2^N 种可能的 SS(换句话说,存在 2N2^N 个由 0011 组成、长度为 NN 的字符串)。找出所有这些 SS 中“最短好路径的长度”之和。

在本题的约束条件下,可以证明:对于任意由 0011 组成的长度为 NN 的字符串 SS,都至少存在一条相对于 SS 的好路径。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a simple connected undirected graph with NN vertices and MM edges. (A graph is said to be simple if it has no multi-edges and no self-loops.)
For i=1,2,,Mi = 1, 2, \ldots, M, the ii-th edge connects Vertex uiu_i and Vertex viv_i.

A sequence (A1,A2,,Ak)(A_1, A_2, \ldots, A_k) is said to be a path of length kk if both of the following two conditions are satisfied:

  • For all i=1,2,,ki = 1, 2, \dots, k, it holds that 1AiN1 \leq A_i \leq N.
  • For all i=1,2,,k1i = 1, 2, \ldots, k-1, Vertex AiA_i and Vertex Ai+1A_{i+1} are directly connected by an edge.

An empty sequence is regarded as a path of length 00.

Let S=s1s2sNS = s_1s_2\ldots s_N be a string of length NN consisting of 00 and 11. A path A=(A1,A2,,Ak)A = (A_1, A_2, \ldots, A_k) is said to be a good path with respect to SS if the following conditions are satisfied:

  • For all i=1,2,,Ni = 1, 2, \ldots, N, it holds that:
    • if si=0s_i = 0, then AA has even number of ii's.
    • if si=1s_i = 1, then AA has odd number of ii's.

There are 2N2^N possible SS (in other words, there are 2N2^N strings of length NN consisting of 00 and 11). Find the sum of "the length of the shortest good path with respect to SS" over all those SS.

Under the Constraints of this problem, it can be proved that, for any string SS of length NN consisting of 00 and 11, there is at least one good path with respect to SS.

Constraints

  • 2N172 \leq N \leq 17
  • N1MN(N1)2N-1 \leq M \leq \frac{N(N-1)}{2}
  • 1ui,viN1 \leq u_i, v_i \leq N
  • The given graph is simple and connected.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uMu_M vMv_M

Output

Print the answer.

Sample Input 1

3 2
1 2
2 3

Sample Output 1

14
  • For S=000S = 000, the empty sequence ()() is the shortest good path with respect to SS, whose length is 00.
  • For S=100S = 100, (1)(1) is the shortest good path with respect to SS, whose length is 11.
  • For S=010S = 010, (2)(2) is the shortest good path with respect to SS, whose length is 11.
  • For S=110S = 110, (1,2)(1, 2) is the shortest good path with respect to SS, whose length is 22.
  • For S=001S = 001, (3)(3) is the shortest good path with respect to SS, whose length is 11.
  • For S=101S = 101, (1,2,3,2)(1, 2, 3, 2) is the shortest good path with respect to SS, whose length is 44.
  • For S=011S = 011, (2,3)(2, 3) is the shortest good path with respect to SS, whose length is 22.
  • For S=111S = 111, (1,2,3)(1, 2, 3) is the shortest good path with respect to SS, whose length is 33.

Therefore, the sought answer is 0+1+1+2+1+4+2+3=140 + 1 + 1 + 2 + 1 + 4 + 2 + 3 = 14.

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