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");
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章