coderforces 22C 构图水题
来源:互联网 发布:淘宝 查看历史价格 编辑:程序博客网 时间:2024/05/18 03:36
点击打开链接
题意:给n个点,m条边,割点为v的一个图,你试图将它还原,不能输出-1,能就将可行的一组输出即可,还有图为联通图
思路:这跟割点没什么关系,直接想想就可以写出来了,先判断能不能组成这样的图,对于一个有一个割点的联通图,如何分配可以使边最多呢,以割点为分界线,左边一部分,右边一部分,可以很直白的知道左边只有一个的时候加的边最多,可以列出个式子,这样右边最多可以为(n-1)*(n-2)/2条边,模拟输出就行了,水题一枚
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const int maxn=300010;int main(){ int n,m,v,a,b; while(scanf("%d%d%d",&n,&m,&v)!=-1){ ll t=(ll)(n-1)*(n-2)/2+1; if(m<n-1||m>t) printf("-1\n"); else{ for(int i=1;i<=n;i++){ if(i!=v) printf("%d %d\n",i,v); } m-=(n-1); if(m==0) break; if(v==1){ int flag=0; for(int i=3;i<=n;i++){ for(int j=i+1;j<=n;j++){ printf("%d %d\n",i,j); m--; if(m==0){ flag=1;break; } } if(flag) break; } }else{ int flag=0; for(int i=2;i<=n;i++){ for(int j=i+1;j<=n;j++){ if(i!=v&&j!=v){ printf("%d %d\n",i,j); m--; if(m==0){ flag=1;break; } } } if(flag) break; } } } } return 0;}
0 0
- coderforces 22C 构图水题
- coderforces 22C 构图水题
- Coderforces 617C Watering Flowers 【暴力】
- coderforces 702C Cellular Network(二分)
- coderforces round#420-C Okabe and Boxes
- Coderforces 20C 最短路记录路径
- coderforces 335B--Palindrome [字符串好题]
- 【CoderForces】#296 Div2 C(线段树+set)
- coderforces 455C 并查集+树的直径
- coderforces--418 div2 C. An impassioned circulation of affection
- poj1149最大流经典构图神题
- ZOJ 1654 (经典二分构图题)
- 文章标题 CoderForces 298A: Snow Footprints(水)
- 文章标题 CoderForces 755A : PolandBall and Hypothesis(水)
- 文章标题 Coderforces 755B : PolandBall and Game(水)
- Coderforces集锦
- Coderforces Round #
- Coderforces Next_Round
- 计算机图形学(二)输出图元_6_OpenGL曲线函数_5_其他曲线
- Scoller的工作原理
- MyEclipse建立SpringMVC入门HelloWorld项目
- php paypal 支付2
- 利用nginx的反向代理和tomcat整合
- coderforces 22C 构图水题
- React Native开源广告轮播组件
- 【深入理解JVM】:垃圾收集算法
- mysql查询时区分大小写的方法
- java IO体系的学习总结
- Cordova安装官方插件
- 【C语言】1-1/2+1/3-1/4……1/n求多项式结果
- Words Reciting 2016.5.4
- 信息无障碍研究机构---企业