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

  1. 【codeforces 755D】PolandBall and Polygon

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

  2. 【codeforces 755B】PolandBall and Game

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

  3. 【codeforces 755A】PolandBall and Hypothesis

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

  4. 【codeforces 755C】PolandBall and Forest

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

  5. 【codeforces 755F】PolandBall and Gifts

    [题目链接]:http://codeforces.com/contest/755/problem/F [题意] n个人; 计划是每个人都拿一个礼物来送给一个除了自己之外的人; 且如果一个人没有送出礼物 ...

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

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

  7. 【codeforces 234F】Fence

    [题目链接]:http://codeforces.com/problemset/problem/234/F [题意] 你有n块板要凃油漆; 然后每块板有高度h[i];(宽度都为1) 然后每块板只能凃同 ...

  8. 【27.91%】【codeforces 734E】Anton and Tree

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

  9. 【codeforces 758B】Blown Garland

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

随机推荐

  1. 快速编译system.img和boot.img的方法【转】

    本文转载自:http://www.cnblogs.com/wanqieddy/archive/2012/10/22/2734024.html 快速编译system.img,可以使用这个命令: #mak ...

  2. linux下的so、o、lo、a、la文件的区别

    o: 编译的目标文件a: 静态库,其实就是把若干o文件打了个包so: 动态链接库(共享库) lo: 使用libtool编译出的目标文件,其实就是在o文件中添加了一些信息la: 使用libtool编译出 ...

  3. MSP430 G2553 Timer 中断总结

    目前总共用到了四个中断向量,我觉得已经把G2553的所有定时器中断都用到了. 定时器有两个,TA0与TA1,每个定时器又有两个中断向量 1,CCR0到达时的中断,在计数模式时候很有用,平时定时器的基本 ...

  4. Sqlserver日期操作

    Sqlserver日期操作 select GETDATE() as '当前日期', DateName(year,GetDate()) as '年', DateName(month,GetDate()) ...

  5. 客户端JavaScript Ajax

    创建: 2017/10/21 完成: 2017/10/23   [TODO] 对Ajax收发各类型数据制作模板 补充跨域通信(cross origin) p457  HTTP通信  HTTP  超文本 ...

  6. P4280 [AHOI2008]逆序对

    传送门 有一个不会证明的贪心:从左到右考虑每一个位置,然后在每一个位置都贪心选取能让该位置构成的逆序对最少的数.判断逆序对的话只要记一下前缀小于等于某数的总数和后缀小于等于某数的总数就行了 //min ...

  7. zb的生日-------搜索 和 动态规划

    简单的贪心算法 : http://love-oriented.com/pack/P01.html  说实话 我是喜欢 动态规划的.......但是省赛迫在眉睫 , 只好先 学 搜索了  ,  赶紧   ...

  8. $P1596 [USACO10OCT]湖计数Lake Counting$

    \(problem\) 其实这题吧\(DFS\)好写一点(大雾 所以就不讲\(DFS\)了 em \(BFS\)的话 主要是 判重. 方向. 队列.(没了吧 至于位置 用两个队列?还是\(pair\) ...

  9. $luogu2375[NOI2014]$

    \(problem\) 其中,\(next[i],next[next[i]],next[next[next[i]]]......\)都是这个前缀串i的公共前后缀,而且只有它们是公共前后缀 那么,我们其 ...

  10. “国家队爷”杯液体战争AI比赛!!__SymenYang

    原帖 这两天一直在搞这个AI,提供的样例更本不是我的风格啊,看不懂更不会改... 所以我自己写了一个AI的平台,现在在不断的修改AI的策略,smart样例还是很容易过的,让line的行走速度变慢一点到 ...