题目链接:http://codeforces.com/contest/745/problem/C

题意:给出n个点m条边,还有k个不能连通的点,问最多能添加几条边。

要知道如果有n个点最多的边是n*(n-1),显然最多的边就是构成一个完全图但是由于有k个点不能连通,

所以先处理一下与k个点链接的几个点,然后再在k个点中选出包含点最多的然后把剩余的点全都与这个

点链接,最后减去m边即可。

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int M = 1e5 + 10;
int a[M] , b[M] , gg;
bool vis[M];
vector<int>vc[M];
bool cmp(int x , int y) {
return x > y;
}
void dfs(int pos) {
vis[pos] = 1;
gg++;
int len = vc[pos].size();
for(int i = 0 ; i < len ; i++) {
if(!vis[vc[pos][i]]) {
vis[vc[pos][i]] = true;
dfs(vc[pos][i]);
}
}
}
int main() {
int n , m , k;
cin >> n >> m >> k;
for(int i = 0 ; i < k ; i++) {
cin >> a[i];
}
for(int i = 0 ; i < m ; i++) {
int x , y;
cin >> x >> y;
vc[x].push_back(y);
vc[y].push_back(x);
}
int count = 0;
int sum = 0;
memset(vis , false , sizeof(vis));
for(int i = 0 ; i < k ; i++) {
vis[a[i]] = true;
gg = 0;
dfs(a[i]);
b[i] = gg;
sum += b[i];
}
sort(b , b + k , cmp);
b[0] += (n - sum);
for(int i = 0 ; i < k ; i++) {
count += (b[i] * (b[i] - 1)) / 2;
}
count -= m;
cout << count << endl;
return 0;
}

Codeforces Round #385 (Div. 2) C - Hongcow Builds A Nation的更多相关文章

  1. Codeforces Round #385 (Div. 2) B - Hongcow Solves A Puzzle 暴力

    B - Hongcow Solves A Puzzle 题目连接: http://codeforces.com/contest/745/problem/B Description Hongcow li ...

  2. Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题

    A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...

  3. Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards

    地址:http://codeforces.com/problemset/problem/744/C 题目: C. Hongcow Buys a Deck of Cards time limit per ...

  4. Codeforces Round #385 (Div. 2) Hongcow Builds A Nation —— 图论计数

    题目链接:http://codeforces.com/contest/745/problem/C C. Hongcow Builds A Nation time limit per test 2 se ...

  5. Codeforces Round #385 (Div. 2) A,B,C 暴力,模拟,并查集

    A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. Codeforces Round #385 (Div. 2)A B C 模拟 水 并查集

    A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...

  7. Codeforces Round #385(div 2)

    A =w= B QwQ C 题意:n个点m条边的无向图,其中有k个特殊点,你在这张图上尽可能多的连边,要求k个特殊点两两不连通,问最多能连多少边 分析:并查集 对原图做一次并查集,找出特殊点所在集合中 ...

  8. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. Transformations 方块转换 USACO 模拟 数组 数学 耐心

    1006: 1.2.2 Transformations 方块转换 时间限制: 1 Sec  内存限制: 128 MB提交: 10  解决: 7[提交] [状态] [讨论版] [命题人:外部导入] 题目 ...

  2. Wtm携手LayUI -- .netcore 开源生态我们是认真的!

    经过WTM团队和LayUI团队多次深入协商,双方于2019年7月29日在北京中国国际展览中心正式达成战略合作意向, 双方签署了战略合作框架协议,LayUI团队承诺使用WTM框架的任何项目都可以免费使用 ...

  3. 控制台出现_ob_:Obsever

    我遇到一个问题:我的代码想让他点击之后得到经纬度坐标数组,然后我就这样写了 然而控制台却读取出了

  4. Spring Boot 支持 Https 有那么难吗?

    https 现在已经越来越普及了,特别是做一些小程序或者公众号开发的时候,https 基本上都是刚需了. 不过一个 https 证书还是挺费钱的,个人开发者可以在各个云服务提供商那里申请一个免费的证书 ...

  5. as更新3.0.1的时候的编译异常

  6. Java连载16-++传参&关系运算符

    一.++再举例 int a = 10; System.out.print(a++);//这里会打印出10,因为他们内部这个print函数有参数相当于参数x=a++ System.out.println ...

  7. Java学习|Exception和Error有什么区别?

    典型回答:      Exception和Error都继承了Throwable类,java中只有Throwable类型的实例才能被Throw(抛出)或者catch(捕获).      Exceptio ...

  8. 如何删除GIT仓库中的敏感信息

    如何删除GIT仓库中的敏感信息 正常Git仓库中应该尽量不包含数据库连接/AWS帐号/巨大二进制文件,否则一旦泄漏到Github,这些非常敏感信息会影响客户的信息安全已经公司的信誉.公司可能其它还有相 ...

  9. python编辑已存在的excel坑: BadZipFile: File is not a zip file

    背景-原代码如下,期望能自动创建excel,并且可以反复调用编辑: import xlwt,osfrom openpyxl.styles import Font, colors class Write ...

  10. 为什么不建议在hbase中使用过多的列簇

    我们知道,hbase表可以设置一个至多个列簇(column families),但是为什么说越少的列簇越好呢? 官网原文: HBase currently does not do well with ...