102445: [AtCoder]ABC244 F - Shortest Good Path

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

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

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

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

An empty sequence is regarded as a path of length $0$.

Let $S = s_1s_2\ldots s_N$ be a string of length $N$ consisting of $0$ and $1$. A path $A = (A_1, A_2, \ldots, A_k)$ is said to be a good path with respect to $S$ if the following conditions are satisfied:

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

There are $2^N$ possible $S$ (in other words, there are $2^N$ strings of length $N$ consisting of $0$ and $1$). Find the sum of "the length of the shortest good path with respect to $S$" over all those $S$.

Under the Constraints of this problem, it can be proved that, for any string $S$ of length $N$ consisting of $0$ and $1$, there is at least one good path with respect to $S$.

Constraints

  • $2 \leq N \leq 17$
  • $N-1 \leq M \leq \frac{N(N-1)}{2}$
  • $1 \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:

$N$ $M$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_M$ $v_M$

Output

Print the answer.


Sample Input 1

3 2
1 2
2 3

Sample Output 1

14
  • For $S = 000$, the empty sequence $()$ is the shortest good path with respect to $S$, whose length is $0$.
  • For $S = 100$, $(1)$ is the shortest good path with respect to $S$, whose length is $1$.
  • For $S = 010$, $(2)$ is the shortest good path with respect to $S$, whose length is $1$.
  • For $S = 110$, $(1, 2)$ is the shortest good path with respect to $S$, whose length is $2$.
  • For $S = 001$, $(3)$ is the shortest good path with respect to $S$, whose length is $1$.
  • For $S = 101$, $(1, 2, 3, 2)$ is the shortest good path with respect to $S$, whose length is $4$.
  • For $S = 011$, $(2, 3)$ is the shortest good path with respect to $S$, whose length is $2$.
  • For $S = 111$, $(1, 2, 3)$ is the shortest good path with respect to $S$, whose length is $3$.

Therefore, the sought answer is $0 + 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

Input

Output

得分:500分

问题描述

给你一个有$N$个顶点和$M$条边的简单连通无向图(一个图被称为简单,如果它没有多边和自环)。

对于$i=1,2,\ldots,M$,第$i$条边连接顶点$u_i$和顶点$v_i$。

一个序列$(A_1, A_2, \ldots, A_k)$被称为长度为$k$的路径,如果满足以下两个条件:

  • 对于所有$i=1,2,\dots,k$,都有$1 \leq A_i \leq N$。
  • 对于所有$i=1,2,\ldots,k-1$,顶点$A_i$和顶点$A_{i+1}$之间由一条边直接连接。

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

让$S = s_1s_2\ldots s_N$是一个由$0$和$1$组成的长度为$N$的字符串。一个路径$A = (A_1, A_2, \ldots, A_k)$被称为关于$S$的好路径,如果满足以下条件:

  • 对于所有$i=1,2,\ldots,N$,都有:
    • 如果$s_i = 0$,那么$A$有偶数个$i$。
    • 如果$s_i = 1$,那么$A$有奇数个$i$。

有$2^N$种可能的$S$(换句话说,有$2^N$个长度为$N$的由$0$和$1$组成的字符串)。对于所有这些$S$,求“关于$S$的最短好路径的长度”的和。

在本问题的约束下,可以证明,对于任何长度为$N$的由$0$和$1$组成的字符串$S$,都至少有一个关于$S$的好路径。

约束条件

  • $2 \leq N \leq 17$
  • $N-1 \leq M \leq \frac{N(N-1)}{2}$
  • $1 \leq u_i, v_i \leq N$
  • 给定的图是简单且连通的。
  • 输入中的所有值都是整数。

输入

输入标准输入,格式如下:

$N$ $M$
$u_1$ $v_1$
$u_2$ $v_2$
$\vdots$
$u_M$ $v_M$

输出

打印答案。


样例输入 1

3 2
1 2
2 3

样例输出 1

14
  • 对于$S = 000$,空序列$()$是关于$S$的最短好路径,其长度为$0$。
  • 对于$S = 100$,$(1)$是关于$S$的最短好路径,其长度为$1$。
  • 对于$S = 010$,$(2)$是关于$S$的最短好路径,其长度为$1$。
  • 对于$S = 110$,$(1, 2)$是关于$S$的最短好路径,其长度为$2$。
  • 对于$S = 001$,$(3)$是关于$S$的最短好路径,其长度为$1$。
  • 对于$S = 101$,$(1, 2, 3, 2)$是关于$S$的最短好路径,其长度为$4$。
  • 对于$S = 011$,$(2, 3)$是关于$S$的最短好路径,其长度为$2$。
  • 对于$S = 111$,$(1, 2, 3)$是关于$S$的最短好路径,其长度为$3$。

因此,所求答案为$0 + 1 + 1 + 2 + 1 + 4 + 2 + 3 = 14$。


样例输入 2

5 5
4 2
2 3
1 3
2 1
1 5

样例输出 2

108

加入题单

算法标签: