codeforces 673D(思维)

来源:互联网 发布:淘宝蓝钻和黄钻的区别 编辑:程序博客网 时间:2024/06/06 00:35

题意:给出一个a,b,c,d。然后求出一个满足a -> …… -> b ,c -> …… -> d的情况,a ,b不能直接相连,c ,d不能直接相连,给出点数和允许的最大的边数。

思路:随意构造出一个满足的情况,你会发现满足最少的边数为n + 1。


除ACBD点的边数为n - 4 - 1,然后还需要6条边,所以至少需要n+1条边。


#include<bits/stdc++.h>using namespace std;typedef pair<int,int> P;const int maxn = 1000 + 10;typedef long long ll;int a,b,c,d;int temp[maxn];int main(){    int n,m;    while( ~ scanf("%d%d",&n,&m))    {        scanf("%d%d%d%d",&a,&b,&c,&d);        if(n == 4 || m < n + 1)        {            puts("-1");continue;        }        int len = 0;        for(int i = 1; i <= n; i ++)        {            if(i != a && i != b && i != c && i != d)                temp[len ++] = i;        }        cout << a << " " << c << " ";        for(int i = 0; i < len; i ++)            cout << temp[i] << " ";        cout << d << " " << b << endl;        cout << c << " " << a << " ";        for(int i = 0; i < len; i ++)            cout << temp[i] << " ";        cout << b << " " << d << endl;    }    return 0;}


原创粉丝点击