Codeforces round#22 C System Administrator Construction Cut-point diagram

Source: Internet
Author: User
Tags integer numbers

Title Description:

Description
Bob got a job as a system administrator in X Corporation. His first task is to connect n servers with the help of M two-way direct connection so it becomes possible to TRANSM It data from one server to any other server via these connections. Each of the direct connection has to link the different servers, each pair of servers should having at most one direct connection. Y Corporation, a business rival of X Corporation, made Bob an offer that he couldn ' t Refuse:bob is asked to connect the Servers in such a-, that's when server with index v fails, the transmission of data between some and other-servers become s 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 SYS Tem.

Output
If It is impossible to connect the servers in the required, output-1. Otherwise output m lines with 2 numbers each-description of all the direct connections in the system. Each direct connection was described by and numbers-indexes of the servers, linked by this direct connection. The servers is numbered from 1. If The answer is isn't unique, output any.

Sample Input
Input

5 6 3

Output

1 22 33 44 51 33 5

Input

6 100 1

Output

-1
Topic Analysis:

Test instructions is the n-point, M-Bar, where Point V is the cut point.
Construct this graph without the output-1 if it cannot be constructed.
First, the ability to construct the graph depends on the size of N and M. The minimum value of M is the condition of the tree m=n-1. The maximum value is the two sub-graphs X and Y after the V-point split are full graphs. The maximum value of m<= (n*n-3*n+4)/2, i.e. M, is obtained by derivation.
Then output the edge connected to the cutting point, in the output of other M-(n-1) bar, but in the output to ensure that the V-point is the cut point of the graph. Therefore, it cannot be output arbitrarily.

The code is as follows:
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>using namespace std;int n,m,v;int main(){    while(scanf("%d%d%d",&n,&m,&v)!=-1)    {        if (m<n-1 || m>((n*n-3*n+4)/2))        {            printf("-1\n");            continue;        }        for(int i=1; i<=n; i++)        {            if (i!=v) printf("%d %d\n",i,v);//n-1条与割点相连的边        }        m-=n-1;        int tt=1;//通过tt保证v是割点        if (v==1) tt=2;        for(int i=1; i<=n && m>0; i++)            if(i!=v && i!=tt)                for(int j=i+1; j<=n &&m>0; j++)                    if(j!=v && j!=tt)                    {                        printf("%d %d\n",i,j);//其它的边                        m--;                    }    }    return 0;}

Codeforces round#22 C System Administrator Construction Cut-point diagram

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.