Codeforces Round 385 (Div. 1)
A
Hongcow Builds A Nation
Codeforces
1500
原题
←B →
翻译中…

Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.

翻译中…

The world can be modeled as an undirected graph with $*n*$ nodes and $*m*$ edges. $*k*$ of the nodes are home to the governments of the $*k*$ countries that make up the world.

翻译中…

There is at most one edge connecting any two nodes and no edge connects a node to itself. Furthermore, for any two nodes corresponding to governments, there is no path between those two nodes. Any graph that satisfies all of these conditions is stable.

翻译中…

Hongcow wants to add as many edges as possible to the graph while keeping it stable. Determine the maximum number of edges Hongcow can add.

翻译中…

Input

翻译中…

The first line of input will contain three integers $*n*$, $*m*$ and $*k*$ ($1 ≤ *n* ≤ 1 000$, $0 ≤ *m* ≤ 100 000$, $1 ≤ *k* ≤ *n*$) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.

翻译中…

The next line of input will contain $*k*$ integers $*c*_{1}, *c*_{2}, ..., *c*_{*k*}$ ($1 ≤ *c*_{*i*} ≤ *n*$). These integers will be pairwise distinct and denote the nodes that are home to the governments in this world.

翻译中…

The following $*m*$ lines of input will contain two integers $*u*_{*i*}$ and $*v*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$). This denotes an undirected edge between nodes $*u*_{*i*}$ and $*v*_{*i*}$.

翻译中…

It is guaranteed that the graph described by the input is stable.

翻译中…

Output

翻译中…

Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable.

翻译中…

Note

翻译中…

For the first sample test, the graph looks like this:

翻译中…

image

翻译中…

Vertices

翻译中…

1

翻译中…

and

翻译中…

3

翻译中…

are special. The optimal solution is to connect vertex

翻译中…

4

翻译中…

to vertices

翻译中…

1

翻译中…

and

翻译中…

2

翻译中…

. This adds a total of

翻译中…

2

翻译中…

edges. We cannot add any more edges, since vertices

翻译中…

1

翻译中…

and

翻译中…

3

翻译中…

cannot have any path between them.

翻译中…

For the second sample test, the graph looks like this:

翻译中…

image

翻译中…

We cannot add any more edges to this graph. Note that we are not allowed to add self-loops, and the graph must be simple.

翻译中…

样例

Input #1
4 1 2
1 3
1 2
Output #1
2
InputCopy OutputCopy
Input #2
3 3 1
2
1 2
1 3
2 3
Output #2
0
InputCopy OutputCopy
题目信息
题号
744A
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。