codeforces22c System Administrator【给定一个割顶输出边 BCC】

Description

Bob got a job as a system administrator in X corporation. His first task was to connectn servers with the help ofm 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 indexv 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 Input

Input

5 6 3

Output

1 2
2 3
3 4
4 5
1 3
3 5

Input

6 100 1

Output

-1

这又是一个乱搞的题QAQ

题意:已知点数、边数、割点的序号(一直以为是割点的个数,没法求了啊==),求是否能构成满足条件的图,输出

做法:首先要判断是否满足条件,我们需要找一个边数和点数的关系,点数的下限一定是等于边数的,点数的上限可以这么想:既然有一个点是割顶,那么把剩下的点分成两团,分别都是完全图,然后割顶是中间的“纽带”,那么想来这两团的个数相等的时候边数最多,上限可求。我们顺着这个思路就可以按顺序写出边啦~~

#include <iostream>
#include<cstdio>
using namespace std;
int n,m,v;
int main()
{
    scanf("%d%d%d",&n,&m,&v);
    {
        if(m<n-1||m>(n*n-3*n+4)/2)
        printf("-1\n");
        else
        {
            int la;
            for(int i=1;i<=n;i++)
            {
                if(i!=v)
                {
                    printf("%d %d\n",i,v);
                    la=i;
                   // break;
                }
            }
            m-=(n-1);
            for(int i=1;i<la&&m;i++)
            {
                for(int j=i+1;j<la&&m;j++)
                {
                    if(i!=v&&j!=v)
                    {
                        printf("%d %d\n",i,j);
                        m--;
                    }

                }
            }
        }
    }
    return 0;
}

写了一天vtk感觉ACM的代码真是短的感人啊==

时间: 2024-08-06 06:48:39

codeforces22c System Administrator【给定一个割顶输出边 BCC】的相关文章

给定一个 hashMap 最终输出最大值的键

1 /** 2 * 3 * 类 描 述:机试题: 给定一个 hashMap 最终输出最大值的键 4 * 作 者: 赵 鹏 5 * 时 间:2017年7月4日 下午6:51:06 6 */ 7 8 public class Test { 9 10 public static void main(String[] args) { 11 12 Map<Integer, Integer> hashMap = new HashMap<Integer , Integer>(); 13 14 /

给定一个数值,输出符合中国人习惯的读法--记一道笔试题

题目:给定一个数字,最大小于一万亿,输出符合中国人习惯的读法,例如: a.12输出:十二 b.102输出:一百零二 c.1002输出:一千零二 d.112输出:一百十二 e.10112输出:一万零一百十二 f.120000000:一亿二千万 g.11021002:一千一百零二万一千零二 h.11020102:一千一百零二万零一百零二 i.1000001:一百万零一 j.1000000001:十亿零一 嗯,一道笔试题,解的很没有节操,没有太好的思路,只能尽力抽取翻译过程中的共有代码,尽量写的不那么

给定一个n,输出从1到n的整数

循环输出 function print(n) { for (let i = 1; i <= n; i++) { console.log(i); } } print(10); 递归输出 function print(n) { if (n) { print(n - 1); console.log(n); } } print(10); 原文地址:https://www.cnblogs.com/wynnzen/p/10349311.html

给定一个日期,输出这个日期是该年的第几天

#include<stdio.h> int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int judge(int a); int main() { int a,b,c,i,sum=0; while(scanf("%d/%d/%d",&a,&b,&c)==3) { sum=0; for(i=0;i<b-1;i++) { sum+=days[i]; if(judge(a) &&i

找割顶的模板

用邻接矩阵写的.自己慢慢理解吧 #include <iostream> #include <cstring> using namespace std; #define CC(c) memset(c, 0, sizeof(c)) const int maxn=5000; int iscut[maxn], g[maxn][maxn], low[maxn], pre[maxn], _pre, n, m; int dfs(int u, int fa) { low[u]=pre[u]=++_

无向图的割顶(poj1523,1144)

割顶:表示无向图中的点,这个点删除之后,原图不在联通,这样的点就是割顶. 怎么求一个图中的割顶呢? 把无向图变成一颗树,dfs时候搜索到在dfs树上的称为树边,搜索是出现后代指向祖先的边称为反向边. 对于根节点,当他存在两个或两个以上的子节点时,那么他就是割顶. 而对于其他节点u,当且仅当u存在一个子节点v,使得v及其所有的后代都没有反向边连回u的祖先时,u是一个割顶. 那么判断就很简单,这里给出两个模板: 题目:poj1523 和 1144都是裸的求割顶的题目 通用模板: #include <

无向图的割顶和桥,无向图的双连通分量入门详解及模板 -----「转载」

https://blog.csdn.net/stillxjy/article/details/70176689 割顶和桥:对于无向图G,如果删除某个节点u后,连通分量数目增加,则称u为图的割顶:如果删除某条边后,连通分量数目增加,则称该边为图的桥.对于连通图删除割顶或桥后都会使得图不再连通 以下我,我们利用dfs的性质来快速找出一个连通图中的所有的割顶和桥 首先我们要引入”时间戳”这个概念: 时间戳:表示在进行dfs时,每个节点被访问的先后顺序.每个节点会被标记两次,分别用pre[],和post

一道有趣的算法题:仿照Excel的列编号,给定一个数字,输出该列编号字符串

       By Long Luo 最近遇到一个算法题: 仿照Excel的列编号,给出一个数字,输出该列编号字符串. 例如:A对应1,Z对应26,AA对应27,AZ对应52 ...... 这个题目是一个典型的26进制思路去处理,但是这个题目里面有很多陷阱,在1, 26, 52等特殊情况进行考虑,经过晚上接近1个小时的编写,完成的代码如下: C++代码如下: #include <iostream> #include <string.h> using namespace std; /

给定一个正整数,编写程序计算有多少对质数的和等于输入的这个正整数,并输出结果。

问题描述:给定一个正整数,编写程序计算有多少对质数的和等于输入的这个正整数,并输出结果.输入值小于1000.如,输入为10,程序应该输出结果为2.(共有两对质数的和为10,分别为(5,5),(3,7)) 附算法代码: public class PrimeNumber { //判断是否是质数 protected boolean isPrimeNumber(int num){ if(num == 2) return true;//2特殊处理 if(num < 2 || num % 2 == 0) r