【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 ...
随机推荐
- Vue学习之路第十篇:简单计算器的实现
前面九篇讲解了vue的一些基础知识,正所谓:学以致用,今天我们将用前九篇的基础知识,来模拟实现计算器的简单功能,项目价值不高,纯粹是为了加深掌握所学知识. 学前准备: 需要掌握JavaScript的e ...
- MySQL 面试题(一)
原文地址:http://www.2cto.com/database/201311/254385.html 作者:黄杉(红黑联盟) 公司招聘MySQL DBA面试心得 1 2年MySQL DBA经 ...
- 小学生都能学会的python(函数)
小学生都能学会的python(函数) 神马是函数 函数: 对功能或者动作的封装 函数的定义 def 函数名(形参列表): 函数体(return) ret = 函数名(实参列表) 函数的返回值 retu ...
- url中jsessionid的理解
(1) 这是一个保险措施 因为Session默认是需要Cookie支持的 但有些客户浏览器是关闭Cookie的 这个时候就需要在URL中指定服务器上的session标识,也就是5F4771183629 ...
- RabbitMQ学习总结(5)——发布和订阅实例详解
一.Publish/Subscribe(发布/订阅)(using the Java Client) 在前面的教程中,我们创建了一个work Queue(工作队列).工作队列背后的假设是每个任务是交付给 ...
- Ubuntu 15.10 安装Qt5.5.1
本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50300447 本人使用的ubuntu系 ...
- cogs 304. [NOI2001] 方程的解数(meet in the middle)
304. [NOI2001] 方程的解数 ★★☆ 输入文件:equation1.in 输出文件:equation1.out 简单对比时间限制:3 s 内存限制:64 MB 问题描述 已 ...
- 5.3.5 namedtuple() 创建命名字段的元组结构
在命名元组里.给每一个元组的位置加入一个名称,而且能够通过名称来訪问.大大地提高可读性,以便写出清晰代码,提高代码的维护性.事实上它就像C++里的结构体. collections.namedtuple ...
- HDU 4308 Contest 1
纯BFS+优先队列扩展. #include <iostream> #include <cstdio> #include <cstring> #include < ...
- leetcode第一刷_Subsets II
要求子集,有很现成的方法.N个数.子集的个数是2^N.每一个元素都有在集合中和不在集合中两种状态,这些状态用[0,pow(2,N)]中每一个数来穷举,假设这个数中的第i位为1,说明当前集合中包括源数组 ...