【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 ...
随机推荐
- FreeCodeCamp初级算法部分学习
Reverse a String 翻转字符串 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序,最后把数组转化成字符串. 你的结果必须得是一个字符串 当你完成不了挑战的时候,记得开大招 ...
- PHP的soap 之 nusoap 的使用
今天不知道为什么想起了soap 这个东西,然后就弄了下,在php上使用的是nusoap. 一些基本的使用,高深的麻烦您自己看手册去 这个软件的下载在http://sourceforge.net/pro ...
- BZOJ 3282 Link Cut Tree (LCT)
题目大意:维护一个森林,支持边的断,连,修改某个点的权值,求树链所有点点权的异或和 洛谷P3690传送门 搞了一个下午终于明白了LCT的原理 #include <cstdio> #incl ...
- Myeclipse关闭JS等文件的验证
点击 window > 右键单击properties,弹出properties界面 然后选择MyEclipse->validation->Excluded Resource下找到不需 ...
- pytorch 4 regression 回归
import torch import torch.nn.functional as F import matplotlib.pyplot as plt # torch.manual_seed(1) ...
- crm 系统项目(三) 业务
1. 项目背景 crm系统是某教育平台正在使用的项目,系统主要为 销售部.运营部.教质部门提供管理平台,随着公司规模的扩展,对公司员工的业务信息量化以及信息化建设越来越重要. crm系统为不同角色的用 ...
- js特效——自动滚动
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- redis基本数据类型和对应的底层数据结构
Redis的数据类型包含string,list,hash,set,sorted set. Redis中定义了一个对象的结构体: /* * Redis 对象 */ typedef struct redi ...
- oracle刚開始学习的人经常使用操作100问
oracle刚開始学习的人经常使用操作100问 1. Oracle安装完毕后的初始口令? internal/oracle sys/change_on_install system/manager ...
- Found conflicts between different versions of the same dependent assembly that could not be resolved
https://stackoverflow.com/questions/24772053/found-conflicts-between-different-versions-of-the-same- ...