Codeforces Round #385 (Div. 2) C - Hongcow Builds A Nation
题目链接: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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #385(div 2)
A =w= B QwQ C 题意:n个点m条边的无向图,其中有k个特殊点,你在这张图上尽可能多的连边,要求k个特殊点两两不连通,问最多能连多少边 分析:并查集 对原图做一次并查集,找出特殊点所在集合中 ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- Consul和Kong的实践(一)
Consul和Kong的实践(一) 这一篇先介绍consul集群,以及consul和应用服务的结合使用,下一篇是和kong网关的结合. 一.Consul的集群安装 以其中一台机器为例: mkdir / ...
- LR有的JMeter也有之二“检查点”
好吧!接着上一篇文章的内容和思路,继续前进. 检查点:简单的来理解一下,上一章讲到,我们对用户名和密码进行了参数化,那么怎样来判断jmeter有没有正确调用test.dat里面的文件呢.当然,我们可以 ...
- Spark 系列(五)—— Spark 运行模式与作业提交
一.作业提交 1.1 spark-submit Spark 所有模式均使用 spark-submit 命令提交作业,其格式如下: ./bin/spark-submit \ --class <ma ...
- 4、一个打了鸡血的for循环(增强型for循环)
对于循环,我们大家应该都不陌生,例如do-while循环,while循环,for循环,今天给大家介绍一个有趣的东西——打了鸡血的for循环(增强型for循环). 首先看代码,了解一下for循环的结构: ...
- 安装yarn实况
[**前情提要**]最近在gayhub上面得到一个开源项目,遂准备研究一下源码,当然第一步就是要把项目运行起来.然后看了一下技术栈,发现包管理工具是使用yarn,以前也听说过yarn但是也没有具体使用 ...
- 二、java实现多线程的方式?
一.同步?异步? 下面两幅图解释了同步异步. 二.实现多线程的方式 1.继承Thread package threaddemo; class CreateThreadDemo extends Thre ...
- Docker 前沿概述
目录 Docker 前沿概述 什么是Docker? Docker的基本概念 容器(Container) -- 镜像运行时的实体 镜像(Image) -- 一个特殊的文件系统 仓库(Repository ...
- Codeforces 436D Pudding Monsters
题意简述 开始有无限长的一段格子,有n个格子种有布丁怪兽,一开始连续的布丁怪兽算一个布丁怪兽. 每回合你可以将一个布丁怪兽向左或右移动,他会在碰到第一个布丁怪兽时停下,并与其合并. 有m个特殊格子,询 ...
- (十九)c#Winform自定义控件-停靠窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- 解决pyinstaller打包可执行文件,存放路径包含中文无法运行的问题
一.实验环境 1.Windows7x64_SP1 2.anaconda2.5.0 + python2.7(anaconda集成,不需单独安装) 3.pyinstaller3.0 二.问题描述 1.使用 ...