Codeforces 350E - Wrong Floyd
来源:互联网 发布:mac 统计软件 编辑:程序博客网 时间:2024/05/16 19:40
简单的构造,通过
#include<bits/stdc++.h>using namespace std;const int maxn = 3123;bool vis[maxn];int getnod(int n){ for(int i = 1;i<=n;i++) if(vis[i] == false) return i; return -1;}int getlef(int n){ for(int i = 1;i<=n;i++) if(vis[i]) return i; return -1;}vector<pair<int,int> > ans;bool check(int n,int m){ int st; if((st = getnod(n)) == -1) return false; int lef = getlef(n); m--; ans.push_back(make_pair(lef,st)); for(int i = 1;i<=n;i++){ if(i == lef) continue; for(int j = i+1 ; j <= n;j++){ if(j == lef) continue; if(m > 0){ m--; ans.push_back(make_pair(i,j)); } } } for(int i = 1;i <= n;i++){ if( i == lef || i == st) continue; if( m > 0 && !vis[i]){ m--; ans.push_back(make_pair(i,lef)); } } return m == 0;}int main(){ int n,m,k; memset(vis,0,sizeof(vis)); scanf("%d %d %d",&n,&m,&k); int x; while(k--){ scanf("%d",&x); vis[x] = true; } if(!check(n,m)){ puts("-1"); } else{ for(auto x : ans){ printf("%d %d\n",x.first,x.second); } } return 0;}
0 0
- Codeforces 350E - Wrong Floyd
- CF 203 div2 E. Wrong Floyd 图论
- codeforce 416 E floyd
- codeforces 416E President's Path floyd+D(递)P(推)
- E文积累_20080319_make the wrong calculation
- Codeforces 295B floyd
- CodeForces 25C(Floyd)
- 【codeforces 510 B + floyd】
- [codeforces]#350E. Correct Bracket Sequence Editor
- Codeforces Round #350 (Div. 2) E 链表
- Codeforces Round #350 (Div. 2) E
- codeforces 163E e-Government
- 【Codeforces 163E】E-Government
- Codeforces 78E Evacuation
- 【dp】codeforces 83E
- Codeforces 124 E
- Codeforces 231E
- Codeforces 231E - Cactus
- 数组和广义表
- eclipse中设置codestyle
- 一些实用的js实用框架,想起来就更新
- 二叉树系列---构造二叉查找树
- 有关打包成可执行jar包后引用jar包中配置文件问题
- Codeforces 350E - Wrong Floyd
- Yum安装时提示保护多库版本
- setInerval 的使用注意事项(JavaScript)
- node.js 版本升级
- Android App层通过JNI从驱动获取Input Event
- js 对象属性名为变量
- hdu1688 Sightseeing(次短路)
- 关于oracle中 != 及 null 使用注意点
- (14)标准库类型vector