

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
りんごさんは 頂点 の連結な無向グラフを持っています。 このグラフにはすでに 本の辺があり、 本目の辺は頂点 と頂点 を繋いでいます。
りんごさんは以下の操作を行うことで、辺を追加しようと思っています。
- 操作:頂点 から辺をちょうど 本辿ることによって頂点 に辿り着けるような をとり、頂点 と頂点 の間に辺を追加する。ただし、すでに頂点 と頂点 の間に辺が存在する場合は辺を追加することはできない。
りんごさんが追加できる辺の本数の最大値を求めて下さい。
制約
- 多重辺や自己ループは存在しない
- 与えられるグラフは連結である
入力
入力は以下の形式で標準入力から与えられる。
出力
追加できる辺の本数の最大値を出力せよ。
入力例 1Copy
6 5 1 2 2 3 3 4 4 5 5 6
出力例 1Copy
4
下の図のように辺を追加していくと 本の辺を追加することができ、これ以上辺を追加することはできません。
入力例 2Copy
5 5 1 2 2 3 3 1 5 4 5 1
出力例 2Copy
5
例えば、以下のような順番で辺を追加することによって 本の辺を追加することができます。
- 頂点 と頂点 の間に辺を追加する。
- 頂点 と頂点 の間に辺を追加する。
- 頂点 と頂点 の間に辺を追加する。
- 頂点 と頂点 の間に辺を追加する。
- 頂点 と頂点 の間に辺を追加する。
Score : points
Problem Statement
Rng has a connected undirected graph with vertices. Currently, there are edges in the graph, and the -th edge connects Vertices and .
Rng will add new edges to the graph by repeating the following operation:
- Operation: Choose and such that Vertex can be reached by traversing exactly three edges from Vertex , and add an edge connecting Vertices and . It is not allowed to add an edge if there is already an edge connecting Vertices and .
Find the maximum possible number of edges that can be added.
Constraints
- The graph has no self-loops or multiple edges.
- The graph is connected.
Input
Input is given from Standard Input in the following format:
Output
Find the maximum possible number of edges that can be added.
Sample Input 1Copy
6 5 1 2 2 3 3 4 4 5 5 6
Sample Output 1Copy
4
If we add edges as shown below, four edges can be added, and no more.
Sample Input 2Copy
5 5 1 2 2 3 3 1 5 4 5 1
Sample Output 2Copy
5
Five edges can be added, for example, as follows:
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .
- Add an edge connecting Vertex and Vertex .