CF744A.Hongcow Builds A Nation

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

红牛(Hongcow)是世界的统治者。作为世界统治者,他希望让各国人民在国内通过公路出行变得更加便捷。

世界可以被建模为一个具有 nn 个节点和 mm 条边的无向图。其中 kk 个节点分别代表构成世界的 kk 个国家的政府所在地。

任意两个节点之间至多存在一条边,且不存在连接节点自身的边(即无自环)。此外,对于任意两个代表政府的节点,它们之间不存在路径。满足上述所有条件的图称为稳定图。

红牛希望在保持图稳定的前提下,尽可能多地添加边。请确定红牛最多可以添加多少条边。

输入格式

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.

输入的第一行包含三个整数 nn、mm 和 kk(1≤n≤1 0001 \leq n \leq 1\,000,0≤m≤100 0000 \leq m \leq 100\,000,1≤k≤n1 \leq k \leq n)——分别表示图中顶点数、边数,以及政府所在地的顶点数。

输入的第二行包含 kk 个整数 c1, c2, …, ckc_1,\,c_2,\,\dots,\,c_k(1≤ci≤n1 \leq c_i \leq n)。这些整数两两不同,表示该世界中政府所在地的节点编号。

接下来的 mm 行每行包含两个整数 uiu_i 和 viv_i(1≤ui, vi≤n1 \leq u_i,\,v_i \leq n),表示节点 uiu_i 与 viv_i 之间存在一条无向边。

保证输入所描述的图是稳定的。

输出格式

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

输出一个整数,表示 Hongcow 在保持图稳定的情况下最多可以添加的边数。

输入输出样例

  • 输入#1

    4 1 2
    1 3
    1 2

    输出#1

    2
  • 输入#2

    3 3 1
    2
    1 2
    1 3
    2 3

    输出#2

    0

说明/提示

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

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:

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.

对于第一个样例测试,图如下所示:

顶点 1 和 3 是特殊顶点。最优方案是将顶点 4 与顶点 1 和 2 相连,共添加 2 条边。我们无法再添加更多边,因为顶点 1 和 3 之间不能存在任何路径。

对于第二个样例测试,图如下所示:

该图中无法再添加任何边。注意:不允许添加自环,且图必须是简单图。

输入解题思路,AI测评打分。不知道怎么写?

首页