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. SSH新学,关于面向对象的看法

    流程:model-->dao-->service-->impService-->action 如果只是操作单个的一个表,比如user表,则都写到user的流程中 如果要操作俩个 ...

  2. Java 常用类String类、StringBuffer类

    常用类 String类.StringBuffer类 String代表不可变的字符序列 "xxxxxxx"为该类的对象 举例(1) public class Test { publi ...

  3. Spring的事务到底该给Dao配置还是给Service配置

    Spring的事务到底该给Dao配置还是给Service配置 Spring事务为业务逻辑进行事务管理,保证业务逻辑上数据的原子性. 事务得根据项目性质来细分:事务可以设置到三个层面(dao层.serv ...

  4. CentOS 7 网卡命名修改为eth0格式

    Linux 操作系统的网卡设备的传统命名方式是 eth0.eth1.eth2等,而 CentOS7 提供了不同的命名规则,默认是基于固件.拓扑.位置信息来分配.这样做的优点是命名全自动的.可预知的,缺 ...

  5. apache反向代理服务器

    1 正向代理: 客户端无法直接访问外部的web,需要在客户端所在的网络内架设一台代理服务器,客户端通过代理服务器访问外部的web(需要在客户端的浏览器中设置代理服务器) 适用于: ①局域网的代理服务器 ...

  6. java结合testng,利用XML做数据源的数据驱动示例

    testng的功能很强大,利用@DataProvider可以做数据驱动,数据源文件可以是EXCEL,XML,YAML,甚至可以是TXT文本.在这以XML为例: 备注:@DataProvider的返回值 ...

  7. 用iptables做代理

    出于安全考虑,Linux系统默认是禁止数据包转发的.配置Linux系统的ip转发功能,打开系统转发功能:echo "1" > /proc/sys/net/ipv4/ip_fo ...

  8. BZOJ 2186 沙拉公主的困惑(预处理逆元+欧拉函数)

    题意:求1-n!里与m!互质的数有多少?(m<=n<=1e6). 因为n!%m!=0,所以题目实际上求的是phi(m!)*n!/m!. 预处理出这些素数的逆元和阶乘的模即可. # incl ...

  9. bzoj1390 [CEOI2008] Fence

    题意 给出n个白点和m个黑点.现在你需要选择一些白点把黑点圈起来.每有一个黑点不能被选出的白点组成的凸包包含就需要付出111的代价,每选出一个白点就需要付出20的代价.要求最小化代价之和 n,m< ...

  10. web项目访问路径上为什么不能写上WebContent

    我们常常在WEB项目中要写很多的访问路径,比如说/good/target.jsp;目录结构中从来不会带有项目目录结构的WebContent?这到底的为什么呢? 我们知道WEB项目是放在容器上运行的,而 ...