【codeforces 755E】PolandBall and White-Red graph
【题目链接】:http://codeforces.com/contest/755/problem/E
【题意】
给你n个节点;
让你在这些点之间接若干条边;构成原图(要求n个节点都联通)
然后分别求出原图和补图(补图也要求联通)的直径r1和r2
然后要求min(r1,r2)==k;
让你求出符合要求的原图的m条边;
【题解】
有个结论;
如果图G的直径超过了3,则它的补图的直径会比3小;
且k=1的时候,是无解的;
因为k=1就说明一张图上只有一条边;
n=2的时候,另外一张图上没边,最小值为0;
n>=3的时候,一张图上没有联通n个点;为-1;
综上k=1的时候无解;
再加上上面那个结论;
可知只有当K=2或K=3的时候可能有解;
①
对于K=2的情况;
只有n>=5的时候才有解;
这个时候;
1-2-3-…-n全部连起来就可以了;
即类似样例2
②
对于K=3的情况;
当N=4的时候
连一条链
1-2-3-4就是符合要求的答案;
因为补图中的
2-3这条路径的最短距离为3;
就以这个为基础;
对于N>=5的情况;
从N=4的情况一个节点一个节点地加;
然后维护那个2-3的最短距离为3
但是你新加了一个点x;
如果不在2和x或3和x之间连一条边的话
2和3之间的最短路径就变成2了;
因为可以2->x->3了
所以
1..3连在一起变成一条链;
然后3和剩余的n-3个孤立的点都分别连一条边;
【Number Of WA】
1
【完整代码】
#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 ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x)
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;
int n,k;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
rei(n),rei(k);
if (k>=4 || k <=1)
return pri(-1<<endl),0;
if (k==2)
{
if (n<=4)
return pri(-1<<endl),0;
if (n>=5)
{
pri(n-1<<endl);
rep1(i,1,n-1)
pri(i<<' '<<i+1<<endl);
}
return 0;
}
if (k==3)
{
if (n<=3)
return pri(-1<<endl),0;
pri(n-1<<endl);
rep1(i,1,3)
pri(i<<' '<<i+1<<endl);
rep1(i,5,n)
pri(3<<' '<<i<<endl);
}
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 755E】PolandBall and White-Red graph的更多相关文章
- 【codeforces 755D】PolandBall and Polygon
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755B】PolandBall and Game
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 755A】PolandBall and Hypothesis
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 755C】PolandBall and Forest
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 755F】PolandBall and Gifts
[题目链接]:http://codeforces.com/contest/755/problem/F [题意] n个人; 计划是每个人都拿一个礼物来送给一个除了自己之外的人; 且如果一个人没有送出礼物 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 234F】Fence
[题目链接]:http://codeforces.com/problemset/problem/234/F [题意] 你有n块板要凃油漆; 然后每块板有高度h[i];(宽度都为1) 然后每块板只能凃同 ...
- 【27.91%】【codeforces 734E】Anton and Tree
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 758B】Blown Garland
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- bzoj3894: 文理分科(还是那道最小割)
3894: 文理分科 题目:传送门 感谢波老师没有来D飞我,让我做出了这题... 题解: 这题其实和我做的上一题(bzoj2132)很像,所以就不写题意了. 依然是那最小割... 这题给出了四个利益矩 ...
- ASP.NET Overview
https://msdn.microsoft.com/en-us/library/4w3ex9c2.aspx ASP.NET is a unified统一的 Web development model ...
- 使用WCF进行跨平台开发之一(WCF的实现、控制台托管与.net平台的调用)
WCF是Windows Communication Foundation的缩写,是微软发展的一组数据通信的应用程序开发接口,它是.NET框架的一部分,是WinFx的三个重要开发类库之一,其它两个是WP ...
- geckofx
geckofx是skybound工作室开发的一个开源的用于方便将gecko引擎(最主要的浏览器是firefox)链接到·net 窗体应用的一个组建. 外文名 geckofx 开发商 skyboun ...
- HDU4336:Card Collector
题意 有n张卡片,每一次 有pi的概率买到第i张卡.求买到所有卡的期望购买次数. n<=20 解析 Solution 1:大力状压(就是步数除以方案数) #include<iostream ...
- Oracle数据库初学者入门教程
Oracle数据库是相对于其他数据库来说比较难的一个.Oracle Database,又名Oracle RDBMS,简称Oracle.是甲骨文公司推出的一款关系数据库管理系统.Oracle数据库系统是 ...
- 《Typecript 入门教程》 1、类
类 使用class + 类名 即可定义一个类,一个类中通常有3个成员:属性.构造函数.方法: 在类内部引用属性或方法事使用this调用,它表示我们访问的是类的成员. 我们使用new构造了Greeter ...
- Android布局属性LayoutParams的理解
在一次笔试中搞混LayoutParams的用法,特来总结一番: LayoutParams继承于Android.View.ViewGroup.LayoutParams.LayoutParams相当于一个 ...
- python 生成器函数.推导式.生成器表达式
一.生成器 什么是生成器,生成器的实质就是迭代器 在python中有三种方式来获取生成器: 1.通过生成器函数 2.通过各种推导式来实现生成器 3.通过数据的转换也可以获取生成器 1 def func ...
- Elasticsearch之CURL命令的HEAD
如果只想检查一些文档是否存在,我们可以使用HEAD来替代GET方法,这样就只会返回HTTP头文件. [hadoop@master elasticsearch-]$ curl -i XHEAD http ...