• codeforces 22C System Administrator(构造水题)


    转载请注明出处: http://www.cnblogs.com/fraud/           ——by fraud

    System Administrator

    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 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 test(s)
    Input
    5 6 3
    Output
    1 2
    2 3
    3 4
    4 5
    1 3
    3 5
    Input
    6 100 1
    Output
    -1

    题意

    给出n的点,m条边,和一个结点v,问能否构造出一个以v为割点的连通图

    将剩余n-1个点分成两部分,1个和n-2个。然后直接搞就行

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <vector>
     4 #include <cstring>
     5 using namespace std;
     6 typedef long long ll;
     7 int main()
     8 {
     9     ios::sync_with_stdio(false);
    10     ll n,m,v;
    11     cin>>n>>m>>v;
    12     ll sum2=(ll)(n-1)*(n-2)/2+1;
    13     if(m<n-1||m>sum2)//((n-1)*(n-2)/2+1))
    14     {
    15         cout<<-1<<endl;
    16     }else{
    17         int s=1;
    18         if(v==1)s++;
    19         vector<int>v1;
    20         for(int i=1;i<=n;i++)
    21         {
    22             if(i!=s)v1.push_back(i);
    23         }
    24         cout<<v<<" "<<s<<endl;
    25         int sz=v1.size();
    26         for(int i=0;i<sz-1;i++)
    27         {
    28             cout<<v1[i]<<" "<<v1[i+1]<<endl;
    29         }
    30         m-=n-1;
    31         for(int i=0;i<sz&&m;i++){
    32             for(int j=i+2;j<sz&&m;j++){
    33                 cout<<v1[i]<<" "<<v1[j]<<endl;
    34                 m--;
    35             }
    36         }
    37     }
    38  
    39     return 0;
    40 }
    代码君
  • 相关阅读:
    linux下安装mysql
    python -- 相对路径、绝对路径、以及路径的获取
    Jekyll 使用入门
    argparse 使用指南
    requests快速入门
    Pandoc中的Markdown语法
    利用Github Pages建立仓库“门面”
    Anaconda使用入门
    Python连接SQL Server数据库
    SQL Server 部署CLR程序集错误`6218`
  • 原文地址:https://www.cnblogs.com/fraud/p/4338841.html
Copyright © 2020-2023  润新知