Codeforces Beta Round #22 (Div. 2 Only)-C. System Administrator

来源:互联网 发布:mac 音乐 编辑:程序博客网 时间:2024/04/30 06:49

原题链接

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 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 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
5 6 3
output
1 22 33 44 51 33 5
input
6 100 1
output
-1


首先必须得是连通图,所以m >= n - 1并且存在割点 所以m <= (n - 2) * (n - 1) / 2 + 1(把一个点分离出去,剩下所有点组成完全图,在把剩下的一个点连到割点上)剩下的点随意分配;

#include <bits/stdc++.h>#define maxn 100005#define MOD 1000000007using namespace std;typedef long long ll;int num[maxn];int main(){//freopen("in.txt", "r", stdin);int n, m, v;scanf("%d%d%d", &n, &m, &v);if(m < n - 1 || m > (ll)(n - 2) * (n - 1) / 2 + 1){puts("-1");return 0;}for(int i = 1; i <= n; i++){num[i] = i;}if(v != 2){swap(num[2], num[v]);}for(int i = 1; i < n; i++){printf("%d %d\n", num[i], num[i+1]);}m -= n - 1;for(int i = 2; i < n; i++){for(int j = i+2; j <= n; j++){if(m == 0) return 0;printf("%d %d\n", num[i], num[j]);m--;}}return 0;}


0 0
原创粉丝点击