F - Shortest Good Path Editorial /

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 500500

問題文

NN 個の頂点と MM 本の辺からなる単純(自己ループおよび多重辺を持たない)かつ連結な無向グラフが与えられます。
i=1,2,,Mi = 1, 2, \ldots, M について、ii 番目の辺は頂点 uiu_i と頂点 viv_i を結びます。

下記の 22 つの条件をともに満たす整数列 (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_N0011 のみからなる長さ NN の文字列とします。 パス A=(A1,A2,,Ak)A = (A_1, A_2, \ldots, A_k) が下記を満たすとき、パス AASS に関する良いパスと呼びます。

  • すべての i=1,2,,Ni = 1, 2, \ldots, N について、次を満たす。
    • si=0s_i = 0 ならば、AA に含まれる ii の個数は偶数である。
    • si=1s_i = 1 ならば、AA に含まれる ii の個数は奇数である。

SS として考えられる文字列(すなわち、0011 のみからなる長さ NN の文字列)は 2N2^N 個ありますが、そのすべてにわたる「 SS に関する良いパスのうち最短のものの長さ」の総和を出力してください。

この問題の制約下において、0011 からなる長さ NN のどのような文字列を SS として選んでも、SS に関する良いパスが少なくとも 11 つ存在することが示せます。

制約

  • 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
  • 与えられるグラフは単純かつ連結
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

NN MM
u1u_1 v1v_1
u2u_2 v2v_2
\vdots
uMu_M vMv_M

出力

答えを出力せよ。


入力例 1Copy

Copy
3 2
1 2
2 3

出力例 1Copy

Copy
14
  • S=000S = 000 のとき、空列 ()()SS に関する最短の良いパスであり、その長さは 00 です。
  • S=100S = 100 のとき、(1)(1)SS に関する最短の良いパスであり、その長さは 11 です。
  • S=010S = 010 のとき、(2)(2)SS に関する最短の良いパスであり、その長さは 11 です。
  • S=110S = 110 のとき、(1,2)(1, 2)SS に関する最短の良いパスであり、その長さは 22 です。
  • S=001S = 001 のとき、(3)(3)SS に関する最短の良いパスであり、その長さは 11 です。
  • S=101S = 101 のとき、(1,2,3,2)(1, 2, 3, 2)SS に関する最短の良いパスであり、その長さは 44 です。
  • S=011S = 011 のとき、(2,3)(2, 3)SS に関する最短の良いパスであり、その長さは 22 です。
  • S=111S = 111 のとき、(1,2,3)(1, 2, 3)SS に関する最短の良いパスであり、その長さは 33 です。

よって、求める答えは 0+1+1+2+1+4+2+3=140 + 1 + 1 + 2 + 1 + 4 + 2 + 3 = 14 です。


入力例 2Copy

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

出力例 2Copy

Copy
108

Score : 500500 points

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 1Copy

Copy
3 2
1 2
2 3

Sample Output 1Copy

Copy
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 2Copy

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

Sample Output 2Copy

Copy
108


2025-03-14 (Fri)
13:11:17 +00:00