题目描述

King Byteasar is the ruler of the whole solar system that contains  planets.

This number is so large that people have abandoned the silly custom of naming the planets and use numbers instead. The planets are thus conveniently numbered from 1 to .

Byteasar's palace is on the planet no. 1, while his military base on the planet no. 2.

A long time ago Byteasar had a teleportation portal established between these two planets, which allows travelling from either planet to another in two hundred and fifty minutes (slightly over four hours).

Nowadays the teleportation technology is more mature, and the recent teleportation devices shorten the travel time to just a single hour. Let us note here, that all the portals, both the Byteasar's old one and the new ones available on the market, are of course bidirectional, and that the teleportation travel time is irrespective of the distance travelled.

Some planets of the system are already connected with these new teleportation portals.

In fact, it is already possible to travel between the planets no. 1 and 2 without using the king's private portal, though this involves several other portals and is thus no faster than the king's portal.

Byteasar finds this rather fortunate, as he believes that such possibility would be a security breach.

The technology itself is increasingly available, and as everyone realises its economic significance, each pair of planets that are not currently directly connected with a portal are petitioning for establishing such a connection. Being a wise ruler, Byteasar intends to give his consent to as many constructions as possible, though keeping himself secure, i.e., not allowing the travel between planets 1 and 2 faster than with his private portal.

Help the king determine how many portals he can agree to.

给一张图,要求你再尽可能的多连边,使得从1到2至少要经过5条边

输入输出格式

输入格式:

Two integers are given in the first line of the standard input,  and  (), separated by a single space, denoting the number of planets in Byteasar's realm and the number of new portals that already exist.

These teleportation portals are described in the  lines that follow.

Each such line contains two integers  and  (), separated by a single space, denoting that there is a teleportation portal of the new kind connecting  and .

No pair of numbers appears twice.

You may assume that the existing network of new portals allows travel from planet no. 1 to planet no. 2, but in no less than 250 minutes.

输出格式:

Your program should print out just a single integer, namely the maximum number of portals Byteasar can agree to without breaching his security.

输入输出样例

输入样例#1: 复制

10 10
1 3
3 5
5 7
7 9
2 9
1 4
4 6
6 8
8 10
2 10
输出样例#1: 复制

10
思路:假设已经完成了所有的建图。
那我可以把最后得到的图中的n个点划分为6个集合:1所在的集合,A,B,C,D,2所在的集合
相邻的两个集合之间的所有的点有连边,同一个集合里的各个点之间有连边,其余的没有边。
首先可以证明1所在的集合={1},因为如果放入了其他的点,他就只能和1还有A连边。
但是如果打他放在A里,他就可以和1,A中所有的点,B中所有的点连边。
同理,可以证明2所在的集合={2};
然后会惊讶的发现,在1和2所在的集合确定好了之后,集合A,D也随之确定了。
因为只有A集合中的点才能向1连边,所以在原图中与1相连的点一定在A集合中,其他的点一定可以不在A集合中(因为C集合不为空集)。
同理,集合D也可以得到。
然后考虑剩下的点,他们两两之间肯定有边相连,所以我们要做的就是让他们尽可能多的向外连边,他们向外连边只有两种情况:
  1.分到B集合里向A连边。
  2.分到C集合里向D连边。
所以在原图中,与A集合中的点有连边的点一定会被分到B集合中。与D集合中的点有连边的点一定会被分到C集合中。
剩下的点一定是按照最优策略分到能连出尽可能多的边的点集中,也就是说,如果A重点的数量比D中的多,就把这些点分到B中,反之分到C中。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 1000010
using namespace std;
int n,m,tot,ans;
int tmp1,tmp2;
int tot1,tot2,tot3;
int belong[MAXN];
int to[MAXN*],net[MAXN*],head[MAXN];
void add(int u,int v){
to[++tot]=v;net[tot]=head[u];head[u]=tot;
to[++tot]=u;net[tot]=head[v];head[v]=tot;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v);
}
for(int i=head[];i;i=net[i])
tot1++,belong[to[i]]=;
for(int i=head[];i;i=net[i])
tot2++,belong[to[i]]=;
tot3=n-tot1-tot2-;
ans=tot1*(tot1-)/+tot2*(tot2-)/+tot3*(tot3-)/+tot1+tot2;
for(int x=;x<=n;x++)
if(!belong[x])
for(int i=head[x];i;i=net[i]){
if(!belong[to[i]]) continue;
if(belong[to[i]]==) tmp1++;
else tmp2++;
break;
}
ans+=tmp1*tot1+tmp2*tot2+(tot3-tmp1-tmp2)*max(tot1,tot2);
cout<<ans-m;
}
 

洛谷 P3505 [POI2010]TEL-Teleportation的更多相关文章

  1. 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)

    洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...

  2. [洛谷P3501] [POI2010]ANT-Antisymmetry

    洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...

  3. 洛谷 P3496 [POI2010]GIL-Guilds

    P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...

  4. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  5. 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解

        这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...

  6. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

  7. [洛谷P3509][POI2010]ZAB-Frog

    题目大意:有$n$个点,每个点有一个距离(从小到大给出),从第$i$个点跳一次,会跳到距离第$i$个点第$k$远的点上(若有两个点都是第$k$远,就跳到编号小的上).问对于从每个点开始跳,跳$m$次, ...

  8. [洛谷P3512 [POI2010]PIL-Pilots]

    题目链接: 传送门走这里 题目分析: 感觉不是很难啊--不像是蓝题(AC量也不像)恶意评分? 少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还 ...

  9. [bzoj2088]P3505 [POI2010]TEL-Teleportation

    洛谷 bzoj 用了分层图的思想 题意 给一张图,要求你再尽可能的多连边,使得从1到2至少要经过5条边 没啥复杂的公式,讲解都在注释里 #include<cstdio> #include& ...

随机推荐

  1. SQL Server存储ntext截断问题

    SQL Server存储ntext截断问题   最近遇到一个问题:将大文本存储到数据库的时候,查询出来的文本却被截断了. 最后百度发现,作者提出 sql server management studi ...

  2. vue项目的一些最佳实践提炼和经验总结

    项目组织结构 ajax数据请求的封装和api接口的模块化管理 第三方库按需加载 利用less的深度选择器优雅覆盖当前页面UI库组件的样式 webpack实时打包进度 vue组件中选项的顺序 路由的懒加 ...

  3. shell中处理用户输入

    1.使用命令行参数 在shell执行的时候命令行中输入的所有参数可以赋值给一些特殊变量,这些变量成为位置变量参数. 包括: $0返回脚本名称.$1为第一个参数.$2为第二个参数 ...$9第九个参数 ...

  4. WHU 1538 Stones II 动态规划

    赛后写的,动态规划,学长和题解,提供了两种状态设计的思路,都写了下……结果在写第二种的时候,不小心把下标的起点写错了,导致WA了无数发…… 无奈啊……每次都是这种错误…… 题意: 大概就是有n块石头, ...

  5. 【VBA研究】用VBA取得EXCEL随意列有效行数

    作者:iamlaosong 用VBA对Excel文件进行处理的时候,keyword段的列号编程时往往是不知道的.须要通过參数设定才干知道,因此.我们编程的时候,就不能用这种语句取有效行数: linen ...

  6. abap选择屏幕上的button

    1.背景:近期在看sap的一些abapDemo,看了一个比較好用的功能.分享一下.希望对用到的兄弟有帮助,主要功能是:在选择屏幕上弹出一个小窗体.放一些button在上面,触发不同button,会处理 ...

  7. Spring Security 4 Method security using @PreAuthorize,@PostAuthorize, @Secured, EL--转

    原文地址:http://websystique.com/spring-security/spring-security-4-method-security-using-preauthorize-pos ...

  8. 分享一段官date函数用法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 如何在VMware中创建虚拟机

    今天给大家分享如何在VMware中创建虚拟机,具体的教程如下.在这里小编提前下载了Ubuntu14.04桌面系统,为后面在虚拟机中安装Ubuntu14.04桌面系统做准备. 1.从官网上或者直接百度上 ...

  10. 【Uva 10118】Free Candies

    [Link]: [Description] 有4堆书; 每本书编号从1..20 每堆书都是N本; 然后每次只能从任意一堆的堆顶拿一本书装到自己的口袋里; 你的口袋最多容纳5本书; 当你的口袋里有两本一 ...