System Administrator(构造,图论)
2 seconds
256 megabytes
standard input
standard output
Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of mtwo-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index v fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.
The first input line contains 3 space-separated integer numbers n, m, v (3 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ v ≤ n), n — amount of servers, m — amount of direct connections, v — index of the server that fails and leads to the failure of the whole system.
If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.
5 6 3
1 2
2 3
3 4
4 5
1 3
3 5
6 100 1
-1
思路:由题意,图为连通图,要使得去除v后,图中至少有两个点不能通信(即此时至少有两个连通分支),则v为割点。
要构造出v为割点的图很容易,将图的顶点集合V分为V1和V2两部分,其中V1包含v,而V2不包含v,且V2中的顶点不和{V1-v}中的任何顶点相邻,而V1和{V2+v}中的顶点又各自两两互通。例子如下(红色圈是v):

程序如何实现?将n个顶点划分为V1和V2两部分,从V1(|V1|>=2)中任选一个点作为v,然后从v出发向其他所有顶点各引一条边,如果不满m条边,就在V1和V2内部连边(V1和V2之间不能连边)直至图中已有m条边。
如何确定什么时候无解?这需要求出在顶点数为n的情况下边数m的最大值和最小值。由于图连通,易知m>=n-1。重点是求m的最大值。假设V1和V2各有k和(n-k)个点,V1内部最多k*(k-1) / 2条边,V2内部最多有 (n-k)*(n-k-1) / 2条边,而V2和v之间最多有n-k条边,则m<=k*(k-1) / 2+ (n-k)*(n-k-1) / 2 + n-k ,由一元二次方程知识知当k与(n+1)/2差的绝对值越大,m的最大值越大,于是k为1或n-1。所以m最大时,V1有n-1个点而V2有一个点。故m<=(n-1)*(n-2)/2+1.于是得n-1 <= m <= (n-1)*(n-2)/2+1.
最终思路:取相异两点v和u,v的意义如前,u是V2的唯一一个顶点,将v与所有其他顶点连边(自然包括与u连边),如果此时边数不足m,在V1内部连边直至边数为m
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std; const int SZ = ;
int n, m, v;
bool vis[SZ]; int main()
{
while(scanf("%d %d %d", &n, &m, &v) != EOF)
{
if(m < n - || m > ((n - ) * (n - )) / + n - )
puts("-1");
else if(n < )
{
puts("1 2");
}
else
{
int u = v - ;
if(v == ) u = ;
for(int i = ; i <= n; i++)
{
if(i != v)
printf("%d %d\n", i, v);
}
m -= (n - );
for(int i = ; i <= n && m; i++)
{
if(i == v || i == u) continue;
for(int j = i + ; j <= n && m; j++)
{
if(j == v || j == u) continue;
printf("%d %d\n", i , j);
m--;
}
}
}
}
return ;
}
System Administrator(构造,图论)的更多相关文章
- codeforces 22C System Administrator(构造水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud System Administrator Bob got a job as a s ...
- 解决方法:An error occurred on the server when processing the URL. Please contact the system administrator
在WINDOWS7或SERVER2008上安装了IIS7.5,调试ASP程序时出现以下错误: An error occurred on the server when processing the U ...
- Requirements of an SAP system administrator
Requirements of an SAP system administrator Have a "proper" attitude Protect and safeguard ...
- the account is currently locked out. The system administrator can unlock it.
今天遇到的问题比较有意思.首先是很久没有打开测试数据库了,今天打开,使用service程序测试的时候出现下面的错误提示:Message: System.Data.SqlClient.SqlExcept ...
- 解决IIS7运行ASP提示错误:An error occurred on the server when processing the URL. Please contact the system administrator
原文:解决IIS7运行ASP提示错误:An error occurred on the server when processing the URL. Please contact the syste ...
- SQL点滴8—the account is currently locked out. The system administrator can unlock it.
原文:SQL点滴8-the account is currently locked out. The system administrator can unlock it. 今天遇到的问题比较有意思. ...
- The Windows account sa does not exist and cannot be provisioned as a SQL Server system administrator
今天遇到一个案例,在使用命令修改一个测试服务器(SQL Server 2014标准版)的服务器排序规则时,遇到了下面错误信息 (具体账号信息脱敏处理,随机生成一个账号密码) The Windows a ...
- cvsnt报错:Administrator: Switch to user failed due to configuration error. Contact your System Administrator
在安装CVSNT一开始用Administrator登录时总是报[login aborted]Switch to user failed due to configuration error. Cont ...
- Sql server 账号被锁住:"the account is currently locked out. The system administrator can unlock it."的解决办法(转载)
今天遇到的问题比较有意思.首先是很久没有打开测试数据库了,今天打开,使用service程序测试的时候出现下面的错误提示:Message: System.Data.SqlClient.SqlExcept ...
随机推荐
- c# 导入第三方插件(例如pdf控件),莫名有时候成功有时候出错
问题情境: 正如标题所述: 解决办法: 怀疑是adobe acrobat 9 pro安装文件出错:重新安装,成功. 在这过程中,尝试过福听阅读器,adobe reader等,均正常. 注:1.第三方的 ...
- CS小分队第一阶段冲刺站立会议(5月11日)
昨日成果:完成了倒计时器的制作,为其添加了声音:并对扫雷游戏的失败添加了动态效果: 遇到的困难:把图片放入picturebox中无法改变图片的大小,音乐格式只能使用.wav,该格式音乐比较大,增加了整 ...
- 基础系列(6)—— C#类和对象
一.类介绍 类(class)是C#类型中最基础的类型.类是一个数据结构,将状态(字段)和行为(方法和其他函数成员)组合在一个单元中.类提供了用于动态创建类实例的定义,也就是对象(objec ...
- "数学口袋精灵"bug
首先要部署这个app项目就是第一步: 一.前提下载并安装JDK 在线图解:手把手教你安装JDK http://www.lvtao.net/server/windows-setup-jdk.h ...
- 【Java】对ArrayList排序
java如何对ArrayList中对象按照该对象某属性排序 (从小到大) 两种方法: 方法一:Comparator<KNNNode> comparator = new Comparator ...
- C语言 aabbcc、abc、fabc、aabc
输入一个字符串,匹配字符串中连续出现的字符串.并且连续个数相等 如输入 aabbcc.abc.fabc.aabc.aabbc 分别输出yes还是no #include<stdio.h>#i ...
- html5兼容
You can download the latest version of HTML5shiv from github or reference the CDN version at https:/ ...
- idea 复制数据库查询结果,粘贴直接生成insert into 语句
遇到一个场景,需要将数据库查询的结果导入到另外一个数据库中,给我的第一感受是,写程序,从数据库A中获取到数据,在插入到数据库B中. 但是Idea 可以直接复制查询结果,然后粘贴生成insert语句. ...
- css 层加透明度后文字依然清晰
background: rgba(, , , !important; /*实现FF背景透明,文字不透明*/ filter: Alpha(opacity=); background: #0a0a0a; ...
- Spring Cloud Sleuth服务跟踪
监控 使用zipkin(https://zipkin.io/) 监控服务构建: (普通的springBoot项目) <!--引入的zipkinServer依赖--> <depende ...