D. Bear and Two Paths
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.

Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:

  • There is no road between a and b.
  • There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for .

On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for .

Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.

Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.

Input

The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively.

The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n).

Output

Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.

Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.

Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note

In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.

题意:看a,b之间,c,d之间是否遍历所有顶点且一次后有路,且路的数目不超过K.

题解:

构造一条a,c……d,b的路

和一条   c,a……b,d的路,最少需要n+1条,所以k>=n+1  且n == 4时,a,b之间和c,d之间都不能有通路,所以n == 4怎么都不行。

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int vis[];
void solve(){
int n,k;
int a,b,c,d;
scanf("%d %d",&n,&k);
scanf("%d%d%d%d",&a,&b,&c,&d);
if(n == || k<n+) printf("-1\n");
else{
vis[a] = vis[b] = vis[c] = vis[d] = ;
printf("%d %d ",a,c);
for(int i = ; i<=n; i++){
if(!vis[i]) printf("%d ",i);
}
printf("%d %d\n",d,b);
printf("%d %d ",c,a);
for(int i = ; i<=n; i++){
if(!vis[i]) printf("%d ",i);
}
printf("%d %d\n",b,d);
}
}
int main()
{
solve();
return ;
}

D. Bear and Two Paths(贪心构造)的更多相关文章

  1. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths 构造

    D. Bear and Two Paths 题目连接: http://www.codeforces.com/contest/673/problem/D Description Bearland has ...

  2. codeforces 673D D. Bear and Two Paths(构造)

    题目链接: D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input ...

  3. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心

    C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...

  4. 贪心/构造/DP 杂题选做Ⅱ

    由于换了台电脑,而我的贪心 & 构造能力依然很拉跨,所以决定再开一个坑( 前传: 贪心/构造/DP 杂题选做 u1s1 我预感还有Ⅲ(欸,这不是我在多项式Ⅱ中说过的原话吗) 24. P5912 ...

  5. VK Cup 2016 D. Bear and Two Paths 模拟

    D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 /* 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 */ /************************************************ ...

  7. 贪心/构造/DP 杂题选做

    本博客将会收录一些贪心/构造的我认为较有价值的题目,这样可以有效的避免日后碰到 P7115 或者 P7915 这样的题就束手无策进而垫底的情况/dk 某些题目虽然跟贪心关系不大,但是在 CF 上有个 ...

  8. 贪心/构造/DP 杂题选做Ⅲ

    颓!颓!颓!(bushi 前传: 贪心/构造/DP 杂题选做 贪心/构造/DP 杂题选做Ⅱ 51. CF758E Broken Tree 讲个笑话,这道题是 11.3 模拟赛的 T2,模拟赛里那道题的 ...

  9. Educational Codeforces Round 8 C. Bear and String Distance 贪心

    C. Bear and String Distance 题目连接: http://www.codeforces.com/contest/628/problem/C Description Limak ...

随机推荐

  1. LeetCode OJ 107. Binary Tree Level Order Traversal II

    Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...

  2. python2.6.6在centos6.4下安装

    1.wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tar.bz2 2. tar xvjf Python-2.6.6.tar.bz2 ...

  3. .NET面试题目一

    简单介绍下ADO.NET和ADO主要有什么改进? 答:ADO以Recordset存储,而ADO.NET则以DataSet表示,ADO.NET提供了数据集和数据适配器,有利于实现分布式处理,降低了对数据 ...

  4. 109.110.100.56 samba用户名 PAS, 密码 111111

    如果修改文件夹名字, 需要更改 cd /etc/samba/smb.conf 然后重启samba service smb restart 如果要修改文件夹权限 chmod -R 777 folder ...

  5. PHP字符串函数试题

    Ctrl+A查看答案 1.把ASCII字符的字符串转换为十六进制值的函数是什么?答:bin2hex($string),例如bin2hex('ab') = 6162 2.ASCII码转字符,字符转ASC ...

  6. chrome浏览器调试功能之后端篇

    作为后端开发人员,可能有很多同学不怎么了解chrome调试功能,而即将成为大神的我们,怎么也得会,知其然更要知其所以然,今天我带领大家好好的梳理一下,chrome浏览器调试,个人把它分成了前端功能和后 ...

  7. jQuery实现父窗口的问题

    因为先前遇到的问题,所以我考虑采用 IFRAME 来隔离不同的脚本,从而实现我需要的效果. 在框架中,我用 JavaScript 获取 JSON 数据,组织成 HTML 代码,最后将其填充至上层文档的 ...

  8. hdu 5344 MZL's xor

    MZL's xor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  9. MonkeyRunner 实现自动点击截屏后与本地图库进行对比输出

    先说下本人是菜鸟,通过网上资料学习,终于调通了MonkeyRunner 实现自动点击截屏后与本地图库进行对比输出,以后做静态UI测试就不需要眼睛盯着看图了,这一切交给MonkeyRunner了. 首先 ...

  10. Python实现删除目录下相同文件

    让我们来分析一下这个问题:首先,文件个数非常多,手工查找是不现实的,再说,单凭我们肉眼,在几千张图片或文件里面找到完全相同的难度也是很大的.所以要用程序实现.那么用程序怎么实现呢?根据什么判断两个文件 ...