题目链接: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. MySql性能优化读书比较<一> 数据类型

    一,选择优化的数据类型 1.更小的通常更好. 更小的数据类型通常占用更少的磁盘,内存和cpu缓存,通常更快. 2.简单就好 简单的数据类型操作,通常需要更少的CPU周期. 3.尽量避免NULL值 列可 ...

  2. 非web下的PowerMockito单元测试

    一.介绍 PowerMockito 可以用来 Mock 掉 final 方法(变量).静态方法(变量).私有方法(变量).想要使用 PowerMockito Mock掉这些内容,需要在编写的测试类上使 ...

  3. 2. 源码分析---SOFARPC客户端服务引用

    我们先上一张客户端服务引用的时序图. 我们首先来看看ComsumerConfig的refer方法吧 public T refer() { if (consumerBootstrap == null) ...

  4. golang const 内itoa 用法详解及优劣分析

    首先itoa 是什么 const 内的 iota是golang语言的常量计数器,只能在常量的表达式中使用,,即const内. iota在const关键字出现时将被重置为0(const内部的第一行之前) ...

  5. 在 树莓派(Raspberry PI) 中使用 Docker 运行 aspnetcore/dotnetcore 应用

    本文主要利用 Microsoft 提供的 Dockerfile 进行安装. 虽然Raspberry PI 3 CPU支持 armv8 指令集 ,但是在 docker info 还是识别为 " ...

  6. SQL Labs刷题补坑记录(less31-less53)

    LESS31: 双引号直接报错,那么肯定可以报错注入,并且也过滤了一些东西,^异或没有过滤,异或真香 -1" and (if(length(database())=8,1,0)) and & ...

  7. [Inno Setup]写入注册表时32位系统和64位系统的路由

    昨天下午组内一位同事跟说,他想在Inno Setup的安装包中写入一个注册表.目标位置是HKLM:\Software\下面创建自己的注册表项.然后说尝试了好几次都不行, 但是往HKCU下面写入却是OK ...

  8. axios异步提交表单数据的不同形式

    踩坑Axios提交form表单几种格式 前后端分离的开发前后端, 前端使用的vue,后端的安全模块使用的SpringSecurity,使用postman测试后端的权限接口时发现都正常,但是使用vue+ ...

  9. 牛客多校训练第八场C.CDMA(思维+构造)

    题目传送门 题意: 输入整数m( m∈2k ∣ k=1,2,⋯,10),构造一个由1和-1组成的m×m矩阵,要求对于任意两个不同的行的内积为0. 题解: Code: #include<bits/ ...

  10. java8(二)方法引用

    方法引用让你可以重复使用现有的方法定义,并像 Lambda 一样进行传递. 方法引用可以被看作仅仅调用特定方法的 Lambda 的一种快捷写法. 事实上,方法引用就是让你根据已有的方法实现来创建 La ...