题目链接: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. 用mongodb 固定集合实现只保留固定数量的记录,自动淘汰老旧数据

    在一个保存report记录的场景中,我们使用MongoDB进行数据存储 example: db: report Collection: daily_report 创建db:  use report; ...

  2. SmartSql使用教程(4)——多库配置与使用

    一.引言 已经几个月没更新了.本来上一章的预告是准备写TypeHandler的相关特性的.但是在准备的时候.SmartSql的作者重构了一下TypeHandler,使得我一下子没搞懂TypeHandl ...

  3. Windbg程序调试系列-索引篇

    最近整理了一下Windbg程序调试系列的文章,做个了索引贴,方便大家查询.搜索: Windbg程序调试系列1-常用命令说明&示例 Windbg程序调试系列1-Mex扩展使用总结 Windbg程 ...

  4. snort规则中byte_test参数详解

    例子: byte_test:4,>,1000,20 这里是从本规则内前面匹配的位置结尾开始,向后偏移20个字节,再获取后面的4个字节的数据,与十进制数据1000进行比较,如果大于1000,就命中 ...

  5. 【Java例题】6.2 日期类的使用

    2.日期类的使用.显示今天的年月日.时分秒和毫秒数.显示今天是星期几.是今年内的第几天.显示本月共几天,今年是不是闰年.显示两个日期的差,包括年月日.时分秒和毫秒差值. package chapter ...

  6. Jquery.form异步上传文件常见问题解决

    Jquery.form常用方法我就不多说,主要说一下在使用过程中碰到的问题 1.提示 “xxxx” is not define 或者"xxx" is not a function ...

  7. 如何用Hexo+Github创建自己的技术博客

    注册一个github GitHub官网.按照一般的网站注册登录执行就好了,不详细说. 安装git 安装很简单,一直下一步 git安装教程 很多教程里都说要配置环境变量,我本人安装过5次左右的git,一 ...

  8. Appium+python自动化(三十二)- 代码写死一时爽,框架重构火葬场 - PageObject+unittest(超详解)

    简介 江湖有言:”代码写死一时爽,框架重构火葬场“,更有人戏言:”代码动态一时爽,一直动态一直爽

  9. HashMap源码分析之面试必备

    ​ 今天我们就面试会问到关于HashMap的问题进行一个汇总,以及对这些问题进行解答. 1.HashMap的数据结构是什么? 2.为啥是线程不安全的? 3.Hash算法是怎样实现的? 4.HashMa ...

  10. Windows Server 2008文件服务器

    下面我们来学习Windows Server 2008文件服务器,文件服务器对于企业是相当重要的,所有的资料都保存在文件服务器上面,对于整个企业来说数据算得上是最重要的东西,下面介绍一下文件服务器的搭建 ...