zoukankan      html  css  js  c++  java
  • 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 }
    代码君
  • 相关阅读:
    安全加固3-加固
    Centos7 64位 -- glibc-2.29 编译升级方法(已成功)
    Centos7 -- glibc 升级失败、意外删除、故意删除后的处理方法
    系统引导修复,grub2下的各种骚作
    linux 升级 5.0.2内核
    kvm虚拟化二: 字符界面管理及 无人值守安装
    kvm虚拟化一: 图形化的管理方式
    Linux rhel7 无线网络配置
    虚拟化简介
    requests模块使用二
  • 原文地址:https://www.cnblogs.com/fraud/p/4338841.html
Copyright © 2011-2022 走看看