System Administrator
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first input line contains 3 space-separated integer numbers nmv (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.

Output

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.

Sample test(s)
input
5 6 3
output
1 2
2 3
3 4
4 5
1 3
3 5
input
6 100 1
output
-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(构造,图论)的更多相关文章

  1. codeforces 22C System Administrator(构造水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud System Administrator Bob got a job as a s ...

  2. 解决方法: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 ...

  3. Requirements of an SAP system administrator

    Requirements of an SAP system administrator Have a "proper" attitude Protect and safeguard ...

  4. the account is currently locked out. The system administrator can unlock it.

    今天遇到的问题比较有意思.首先是很久没有打开测试数据库了,今天打开,使用service程序测试的时候出现下面的错误提示:Message: System.Data.SqlClient.SqlExcept ...

  5. 解决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 ...

  6. 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. 今天遇到的问题比较有意思. ...

  7. The Windows account sa does not exist and cannot be provisioned as a SQL Server system administrator

    今天遇到一个案例,在使用命令修改一个测试服务器(SQL Server 2014标准版)的服务器排序规则时,遇到了下面错误信息 (具体账号信息脱敏处理,随机生成一个账号密码) The Windows a ...

  8. 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 ...

  9. Sql server 账号被锁住:"the account is currently locked out. The system administrator can unlock it."的解决办法(转载)

    今天遇到的问题比较有意思.首先是很久没有打开测试数据库了,今天打开,使用service程序测试的时候出现下面的错误提示:Message: System.Data.SqlClient.SqlExcept ...

随机推荐

  1. 每日Scrum--No.2

    Yesterday:找地图 Today: 找到最适合我们软件的地图版本 Problem:找不到特别匹配的版本

  2. Linux 环境下svn 服务器搭建

    可使用自己下载的svn安装包,但要安装相关依赖包,yum 安装源提供的稳定版本svn 1.yum -y install subversion 2.创建本地库 mkdir -p /var/svn svn ...

  3. Linux 下web开发环境搭建-jdk环境搭建

    Centos 7 附:windows 下jdk环境变量 CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools ...

  4. html个人网页

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. lintcode-24-LFU缓存

    24-LFU缓存 LFU是一个著名的缓存算法 实现LFU中的set 和 get 样例 capacity = 3 set(2,2) set(1,1) get(2) >> 2 get(1) & ...

  6. springMVC 流程

    springMVC流程控制 SpringMVC流程 web.xml 中配置 org.springframework.web.servlet.DispatcherServlet 这一步其实和spring ...

  7. 查看sqlserver数据库的编码格式

    查询语句:SELECT  COLLATIONPROPERTY('Chinese_PRC_Stroke_CI_AI_KS_WS', 'CodePage'): 查询结果: 936 简体中文GBK 950 ...

  8. 还原 listagg/wm_concat 后的数据 pack_split_listatt ;

    1.创建表并制作测试数据: --创建测试表 : CREATE TABLE split_table ( NAME ), ID ) ); --准备测试数据 : INSERT INTO split_tabl ...

  9. webgl glsl

    GLSL是什么? GLSL是运行在GPU上的着色器语言 GLSL有自己的语法,跟js有些不同. GLSL是一个强类型的语言,所以在写着器语言时,必须要用强类型,强类型,强类型,强类型 GLSL是着色器 ...

  10. 我以前不知道的 Session

    之前只知道 Session 是服务器与客户端的一个会话,有默认过期时间,是服务器端的技术,与之对应的是 Cookie 技术,是客户端技术. 下面的几点是之前不知道的:[或者是忘了] 1 . Sessi ...