转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

System Administrator

Bob got a job as a system administrator in X corporation. His first task was to connect n servers with the help of m two-way direct connection so that it becomes possible to transmit data from one server to any other server via these connections. Each direct connection has to link two different servers, each pair of servers should have at most one direct connection. Y corporation, a business rival of X corporation, made Bob an offer that he couldn't refuse: Bob was asked to connect the servers in such a way, that when server with index v fails, the transmission of data between some other two servers becomes impossible, i.e. the system stops being connected. Help Bob connect the servers.

Input

The first input line contains 3 space-separated integer numbers n, m, v (3 ≤ n ≤ 105, 0 ≤ m ≤ 105, 1 ≤ v ≤ n), n — amount of servers, m — amount of direct connections, v — index of the server that fails and leads to the failure of the whole system.

Output

If it is impossible to connect the servers in the required way, output -1. Otherwise output m lines with 2 numbers each — description of all the direct connections in the system. Each direct connection is described by two numbers — indexes of two servers, linked by this direct connection. The servers are numbered from 1. If the answer is not unique, output any.

Sample test(s)
Input
  1. 5 6 3
Output
  1. 1 2
    2 3
    3 4
    4 5
    1 3
    3 5
Input
  1. 6 100 1
Output
  1. -1

题意

给出n的点,m条边,和一个结点v,问能否构造出一个以v为割点的连通图

将剩余n-1个点分成两部分,1个和n-2个。然后直接搞就行

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cstring>
  5. using namespace std;
  6. typedef long long ll;
  7. int main()
  8. {
  9. ios::sync_with_stdio(false);
  10. ll n,m,v;
  11. cin>>n>>m>>v;
  12. ll sum2=(ll)(n-)*(n-)/+;
  13. if(m<n-||m>sum2)//((n-1)*(n-2)/2+1))
  14. {
  15. cout<<-<<endl;
  16. }else{
  17. int s=;
  18. if(v==)s++;
  19. vector<int>v1;
  20. for(int i=;i<=n;i++)
  21. {
  22. if(i!=s)v1.push_back(i);
  23. }
  24. cout<<v<<" "<<s<<endl;
  25. int sz=v1.size();
  26. for(int i=;i<sz-;i++)
  27. {
  28. cout<<v1[i]<<" "<<v1[i+]<<endl;
  29. }
  30. m-=n-;
  31. for(int i=;i<sz&&m;i++){
  32. for(int j=i+;j<sz&&m;j++){
  33. cout<<v1[i]<<" "<<v1[j]<<endl;
  34. m--;
  35. }
  36. }
  37. }
  38.  
  39. return ;
  40. }

代码君

codeforces 22C System Administrator(构造水题)的更多相关文章

  1. CodeForces 22C System Administrator

    把v和2结点交换, 1和v连,其它点和v之间能够互相连. #include <iostream> #include <cstdlib> #include <cstring ...

  2. 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root

    题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algori ...

  3. codeforces 659A A. Round House(水题)

    题目链接: A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. codeforces 577B B. Modulo Sum(水题)

    题目链接: B. Modulo Sum time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #367 (Div. 2)---水题 | dp | 01字典树

    A.Beru-taxi 水题:有一个人站在(sx,sy)的位置,有n辆出租车,正向这个人匀速赶来,每个出租车的位置是(xi, yi) 速度是 Vi;求人最少需要等的时间: 单间循环即可: #inclu ...

  6. codeforces 696A Lorenzo Von Matterhorn 水题

    这题一眼看就是水题,map随便计 然后我之所以发这个题解,是因为我用了log2()这个函数判断在哪一层 我只能说我真是太傻逼了,这个函数以前听人说有精度问题,还慢,为了图快用的,没想到被坑惨了,以后尽 ...

  7. CodeForces 589I Lottery (暴力,水题)

    题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...

  8. Codeforces Gym 100286G Giant Screen 水题

    Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...

  9. codeforces 710A A. King Moves(水题)

    题目链接: A. King Moves 题意: 给出king的位置,问有几个可移动的位置; 思路: 水题,没有思路; AC代码: #include <iostream> #include ...

随机推荐

  1. Http Clinet使用

    Http Client是个apache下的一个开源包,用于使用http协议访问服务的java代码编写. Http Client的主要功能: (1)实现了所有 HTTP 的方法(GET,POST,PUT ...

  2. Combination Sum,Combination Sum II,Combination Sum III

    39. Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique co ...

  3. 永久存储:腌制一缸美味的泡菜 - 零基础入门学习Python031

    永久存储:腌制一缸美味的泡菜 让编程改变世界 Change the world by program 从一个文件里读取字符串非常简单,但如果想要读取出数值,那就需要多费点儿周折.因为无论是read() ...

  4. Google机器学习笔记(七)TF.Learn 手写文字识别

    转载请注明作者:梦里风林 Google Machine Learning Recipes 7 官方中文博客 - 视频地址 Github工程地址 https://github.com/ahangchen ...

  5. BZOJ 1977 次小生成树(最近公共祖先)

    题意:求一棵树的严格次小生成树,即权值严格大于最小生成树且权值最小的生成树. 先求最小生成树,对于每个不在树中的边,取两点间路径的信息,如果这条边的权值等于路径中的权值最大值,那就删掉路径中的次大值, ...

  6. 编程是一项需要时间来掌握的技能(Anders的经验)

    Anders现在每天仍然花大量的时间实际写代码,并且未来会一直写下去.他很清醒的知道自己长处:“相比起管理,我还是更擅长于编程.” 事实上,Anders的成名之作Turbo Pascal通过出售软件授 ...

  7. 解决Qt5 Creator无法切换输入法(fcitx),不能录入汉字问题

    笔者系统环境,Ubuntu 14.04,输入法fcitx下搜狗输入法. 其它非Ubuntu linux发行版,不通过软件源安装Qt5,从Qt官网http://qt-project.org/下载安装包, ...

  8. Ubuntu 16.04 LTS 正式发布:系统将持续更新5年

    Canonical 刚刚正式发布了Ubuntu 16.04 LTS (Xenial Xerus),这是一个长期支持版本,官方会提供长达5年的技术支持(包括常规更新/Bug修复/安全升级),一直到202 ...

  9. Using HTML5 audio and video

    From:https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_HTML5_audio_and_video Using HTML5 ...

  10. CentOS6.4安装mplayer

    1.准备软件 mplayer官网:http://www.mplayerhq.hu/design7/news.html RPM Fusion网址:http://rpmfusion.org/ EPEL网址 ...