Codeforces Beta Round #22 (Div. 2 Only)--C. System Administrator--构造割点为V、边有M条的图

C. System Administrator

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 vfails, 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 nmv (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.

Examples

input

Copy

5 6 3

output

Copy

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

input

Copy

6 100 1

output

Copy

-1

构造割点为V、边有M条的图

思路:考虑孤立某个节点,使得V-X只有一条边。

若V=N,那么mark=N-1 否则mark=N。

不让其他点向mark点连边。

考虑到m应该>=n-1,能够形成树,并且m<= (n-1)*(n-2)+1,就是除去孤立点形成完全图的边数+1。

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include<iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#define ll long long
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
//priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 200500+6;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
const int INF=99999999;
int main()
{
    int n,m,v;
    while(scanf("%d %d %d",&n,&m,&v)!=EOF)
    {
        int mark;
        ll maxx=(n-1)*(n-2)/2+1;
        if(m>=n-1&&m<=maxx)
        {
            mark=(v==n?n-1:n);
            int s=1;
            printf("%d %d\n",v,mark);
            rep(i,1,n-1)
            {
                if(s<m)
                {
                    rep(j,i+1,n)
                    {
                        if(j==mark)continue;
                        printf("%d %d\n",i,j);
                        s++;
                        if(s==m)break;
                    }
                }
            }
        }else
        {
            printf("-1\n");
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值