【codeforces 22C】 System Administrator
【题目链接】:http://codeforces.com/problemset/problem/22/C
【题意】
给你n个点;
要求你构造一个含m条边的无向图;
使得任意两点之间都联通;
同时,要求这张图;
在删掉第x个节点之后,会有一些点之间变成不联通的;
(两点之间最多连一条边)
【题解】
把v和某一个点x连在一起;
然后除了这两个点之外的其他n-2个点;
先每一个点都和v连一条边;
保证联通;
然后如果边数还有剩余;
就在那剩余的n-2个点之间一直连边,直到练成一个团(n-2个点的完全图);
这样边的个数就是有限定的了;
即
n-1<=m<=1+C(N-1,2)
这样做的目的就是,删掉v之后,x和整个团里面的点都不联通了;
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;
LL n,m,v;
int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> m >> v;
if (m < n-1 || m > (n-1)*(n-2)/2 + 1)
cout << -1 << endl;
else{
int la = 1;
rep1(i,1,n)
if (i != v){
cout << i <<' '<< v<<endl;
la = i;
}
m-=(n-1);
for (int i = 1;m>0 && i <= la-1;i++){
if (i!=v)
for (int j = i+1;m>0 && j <= la-1;j++)
if (i!=v && j!=v){
cout <<i<<' '<<j<<endl;
m--;
}
}
}
return 0;
}
【codeforces 22C】 System Administrator的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【63.73%】【codeforces 560A】Currency System in Geraldion
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 527B】Error Correct System
[题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...
- 【42.59%】【codeforces 602A】Two Bases
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750F】New Year and Finding Roots
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【27.66%】【codeforces 592D】Super M
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 761D】Dasha and Very Difficult Problem
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【20.51%】【codeforces 610D】Vika and Segments
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
随机推荐
- 基于better-scroll封装一个上拉加载下拉刷新组件
1.起因 上拉加载和下拉刷新在移动端项目中是很常见的需求,遂自己便基于better-scroll封装了一个下拉刷新上拉加载组件. 2.过程 better-scroll是目前比较好用的开源滚动库,提供很 ...
- [BOI2007]摩基亚
题目:洛谷P4390.BZOJ1176. 题目大意: 给你一个\(W\times W\)的矩阵,初始每个数都为\(S\).现在有若干操作: 1. 给某个格子加上一个值:2. 询问某个子矩阵的值的和:3 ...
- 解决tpcc_load 报错 error while loading shared libraries: libmysqlclient.so.20
在刚开始导入tpcc数据仓库时,可能会遇到 error while loading shared libraries: libmysqlclient.so.20这个错误,找不到库文件. 但是,通过fi ...
- 【codeforces 757E】Bash Plays with Functions
[题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...
- libvips
libvips : an image processing library libvips is a 2D image processing library. Compared tosimilar l ...
- LaTeX 基本的公式符号命令
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50240237 下面列出一些基本的LaT ...
- oracle间隔分区
http://blog.csdn.net/rznice/article/details/55048876
- 深入理解Dalvik虚拟机- 解释器的执行机制
Dalvik的指令运行是解释器+JIT的方式,解释器就是虚拟机来对Javac编译出来的字节码,做译码.运行,而不是转化成CPU的指令集.由CPU来做译码,运行.可想而知.解释器的效率是相对较低的,所以 ...
- 终结者:负载均衡之Nginx(一)
相信非常多人都听过Nginx.这个小巧的东西能够和Apache及IIS相媲美.那么它有什么作用呢?一句话.它是一个减轻Web应用server(如Tomcat)压力和实现Web应用ser ...
- 前端project师养成记:开发环境搭建(Sublime Text必备插件推荐)
为了让自己更像一个前端project师,决定从开发环境開始武装自己. 本文将介绍前段project师开发的一些利器的安装步骤,主要包含了: 1.Node.js的安装 2.Grunt的安装及经常使用插件 ...