

Time Limit: 4 sec / Memory Limit: 1024 MB
配点 : 点
問題文
個の頂点と 本の辺からなる単純(自己ループおよび多重辺を持たない)かつ連結な無向グラフが与えられます。
について、 番目の辺は頂点 と頂点 を結びます。
下記の つの条件をともに満たす整数列 を長さ のパスと呼びます。
- すべての について、 。
- すべての について、頂点 と頂点 は辺で直接結ばれている。
空列も長さ のパスとみなします。
を と のみからなる長さ の文字列とします。 パス が下記を満たすとき、パス を に関する良いパスと呼びます。
- すべての について、次を満たす。
- ならば、 に含まれる の個数は偶数である。
- ならば、 に含まれる の個数は奇数である。
として考えられる文字列(すなわち、 と のみからなる長さ の文字列)は 個ありますが、そのすべてにわたる「 に関する良いパスのうち最短のものの長さ」の総和を出力してください。
この問題の制約下において、 と からなる長さ のどのような文字列を として選んでも、 に関する良いパスが少なくとも つ存在することが示せます。
制約
- 与えられるグラフは単純かつ連結
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
3 2 1 2 2 3
出力例 1Copy
14
- のとき、空列 は に関する最短の良いパスであり、その長さは です。
- のとき、 は に関する最短の良いパスであり、その長さは です。
- のとき、 は に関する最短の良いパスであり、その長さは です。
- のとき、 は に関する最短の良いパスであり、その長さは です。
- のとき、 は に関する最短の良いパスであり、その長さは です。
- のとき、 は に関する最短の良いパスであり、その長さは です。
- のとき、 は に関する最短の良いパスであり、その長さは です。
- のとき、 は に関する最短の良いパスであり、その長さは です。
よって、求める答えは です。
入力例 2Copy
5 5 4 2 2 3 1 3 2 1 1 5
出力例 2Copy
108
Score : points
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 1Copy
3 2 1 2 2 3
Sample Output 1Copy
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 2Copy
5 5 4 2 2 3 1 3 2 1 1 5
Sample Output 2Copy
108