【题目链接】: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的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【63.73%】【codeforces 560A】Currency System in Geraldion

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 527B】Error Correct System

    [题目链接]:http://codeforces.com/contest/527/problem/B [题意] 给你两个字符串; 允许你交换一个字符串的两个字符一次: 问你这两个字符串最少会有多少个位 ...

  4. 【42.59%】【codeforces 602A】Two Bases

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 750F】New Year and Finding Roots

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 【27.66%】【codeforces 592D】Super M

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【codeforces 761D】Dasha and Very Difficult Problem

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【20.51%】【codeforces 610D】Vika and Segments

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

随机推荐

  1. [Linux C]系统调用(system call)和库函数调用(Library functions)

    Linux 下对文件操作有两种方式:系统调用(system call)和库函数调用(Library functions).系统调用实际上就是指最底层的一个调用,在 linux 程序设计里面就是底层 调 ...

  2. HDU 2048 神、上帝以及老天爷( 错排 )

    链接:传送门 思路:错排模板,典型错排问题,n个人所有人都不会抽到自己的方案数为 Dn = (n-1) * (Dn-1 + Dn-2) /******************************* ...

  3. a标签设置高度不生效问题

    <a>是内联元素 必须设置成块级元素block 才能有width和height 不过你可以又定义display:block再定义成display:inline 以避免在IE6下产生BUG ...

  4. poj 3420 Quad Tiling (状压dp+多米诺骨牌问题+矩阵快速幂)

    还有这种操作?????? 直接用pre到now转移的方式构造一个矩阵就好了. 二进制长度为m,就构造一个长度为1 << m的矩阵 最后输出ans[(1 << m) - 1][( ...

  5. document.documentElement与body下clientHeight,scrollHeight等区别

    本次说明仅在chrom环境下,ie等其他浏览器可能不同 1获取显示屏高度(pc和移动端,屏幕分辨率px) window.screen.height => 这个好理解,不多说. 2获取浏览器可视窗 ...

  6. 【 【henuacm2016级暑期训练】动态规划专题 P】Animals

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 第i只动物如果饲养它的话. 代价是固定的就是(n-i+1)a[i] 所以相当于给你n个物品,每个物品的重量为(n-i+1)a[i], ...

  7. [Python + Unit Testing] Write Your First Python Unit Test with pytest

    In this lesson you will create a new project with a virtual environment and write your first unit te ...

  8. cocos2d-x3.2 下使用多线程

    事实上在cocos2dx下使用多线程事实上就是用C++去写,这里提供几个简单的样例: 原文地址:http://blog.csdn.net/qqmcy/article/details/36227377 ...

  9. hdu1213 How Many Tables(并查集)

    How Many Tables Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  10. inheritance in kentico

    Visual inheritance http://devnet.kentico.com/docs/7_0/devguide/index.html?visual_inheritance.htm The ...