题目链接: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. CountDownLatch实现多线程并发请求

    package com.test; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Dat ...

  2. javascript+jQuery补充

    一.jQuery事件绑定 <div class='c1'> <div> <div class='title'>菜单一</div> <div cla ...

  3. java高并发系列 - 第21天:java中的CAS操作,java并发的基石

    这是java高并发系列第21篇文章. 本文主要内容 从网站计数器实现中一步步引出CAS操作 介绍java中的CAS及CAS可能存在的问题 悲观锁和乐观锁的一些介绍及数据库乐观锁的一个常见示例 使用ja ...

  4. 佳木斯集训Day7

    毒瘤出题人!!! T2的题面和样例不一样,所以我挂了(没错这就是我写模拟写挂了的理由) T1 大水题,懒得解释了,五分钟AC #include <bits/stdc++.h> #defin ...

  5. SpringBoot-Admin的使用

    [**前情提要**]Spring Boot Actuator 提供了对单个 Spring Boot 应用的监控,信息包含应用状态.内存.线程.堆栈等,比较全面的监控了 Spring Boot 应用的整 ...

  6. 有关element 的一些问题(随时更新)

    <el-input></el-input> input  组件中官方自带的change时间是监听失去焦点之后的value变化,要想一只监听value的值变化的话需要使用  @i ...

  7. 为什么双重检查锁模式需要 volatile ?

    双重检查锁定(Double check locked)模式经常会出现在一些框架源码中,目的是为了延迟初始化变量.这个模式还可以用来创建单例.下面来看一个 Spring 中双重检查锁定的例子. 这个例子 ...

  8. (三十九)c#Winform自定义控件-面包屑导航

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  9. 如何处理scrum中未完成的用户故事?

    你听过柏林新建机场的故事吗?机场原定2006年开工,2007年启用,但由于机场建设过程中到处出现施工和安全问题,补东墙漏西墙,导致工期一拖再拖,预算一涨再涨,以至于2019年了还没开张,预计开业时间已 ...

  10. 实战SpringCloud响应式微服务系列教程(第四章)

    接上一篇: 实战SpringCloud响应式微服务系列教程(第一章) 实战SpringCloud响应式微服务系列教程(第二章) 实战SpringCloud响应式微服务系列教程(第三章) 1.1.4 引 ...