【题目链接】: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. 《Exception》第八次团队作业:Alpha冲刺(第三天)

      一.项目基本介绍 项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 团队名称 Exception 作业学习目标 1.掌握软件测试基础技术.2.学习迭代式增 ...

  2. SUSE Linux Enterprise 11 SP4系统安装过程 字符界面

    首先开启虚拟机之后显示这个界面: (1) 进入之后显示下面界面,点击Installation安装. (2)进入Welcome界面,选择语言,默认Einglish(US)不需要改动:点击I Agree ...

  3. NYIST 1030 Yougth's Game[Ⅲ]

    Yougth's Game[Ⅲ]时间限制:3000 ms | 内存限制:65535 KB难度:4 描述有一个长度为n的整数序列,A和B轮流取数,A先取,每次可以从左端或者右端取一个数,所有数都被取完时 ...

  4. 创业笔记-Node.js入门之阻塞与非阻塞

    阻塞与非阻塞 正如此前所提到的,当在请求处理程序中包括非阻塞操作时就会出问题.但是,在说这之前,我们先来看看什么是阻塞操作. 我不想去解释“阻塞”和“非阻塞”的具体含义,我们直接来看,当在请求处理程序 ...

  5. SQL SERVER-主键的建立和删除

    PRIMARY KEY 约束唯一标识数据库表中的每条记录.主键必须包含唯一的值.主键列不能包含 NULL 值.每个表都应该有一个主键,并且每个表只能有一个主键.主键约束操作包含了添加约束和删除约束,修 ...

  6. HDU 4336

    概率DP期望,逆推即可.使用状态压缩. 注意,要全部输出...看DIS才发现题目输出是个坑.. #include <iostream> #include <cstdio> #i ...

  7. C/C++拾遗(一):关于数组的指针和数组元素首地址的一道经典题

    代码例如以下: #include <stdio.h> int main(void) { int a[5] = {1, 2, 3, 4, 5}; int *ptr = (int *)(&am ...

  8. sqlite学习笔记11:C语言中使用sqlite之删除记录

    最后一节,这里记录下怎样删除数据. 前面全部的代码都继承在这里了,在Ubuntu14.04和Mac10.9上亲測通过. #include <stdio.h> #include <st ...

  9. po层和vo层中po和vo是什么意思

    POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称. pojo 是Plain Old Java Ob ...

  10. hdoj 1013Digital Roots

     /*Digital Roots Problem Description The digital root of a positive integer is found by summing th ...