题干:

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 = avn = 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 ndistinct cities u1, u2, ..., un that u1 = cun = 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 nk and four distinct cities abcd, 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 abc 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 ndistinct 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 kdistinct 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.

题目大意:

给你一个包含N个点的无向图,要求我们用小于等于K条边来构造出这个图。

这个图有两对起点和终点:第一对的起点a,终点b。第二对的起点c,终点d;

现在要求构造出的图,a和b之间没有直接相连的边,c和d之间没有直接相连的边。

但是从a到b有一条路径,a作为起点,b作为终点,路径上包含所有点(1.2.3.4.5..............N)。

同理,从c到d也有一条路径,c作为起点,d作为终点,路径上也包含所有点。

如果可以构造出来,输出这两条路径经过的点;反之输出-1。

解题报告:

因为是构造题,并且要求能否在K条边之内构造出来,所以肯定要构造一个最少边数的解。首先a为起点b为终点的肯定需要n-1条边,c到d还需要连边,所以肯定最少需要n条边。但是n条边肯定无法使得ac都可以当起点,bd当终点。所以需要n+1条边,发现可以构造,且总可以构造,也就是a->c->a->...->b->d->b的一条路径,即可满足条件,并且第二个a和b中间必须要有点,这也就要求点数必须>5,否则不满足ab不相邻的条件,于是这样构造即可。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int n,k,a,b,c,d;
int main()
{cin>>n>>k;cin>>a>>b>>c>>d;if(k < n+1 || n == 4) {printf("-1\n");return 0;} printf("%d %d ",a,c);for(int i = 1; i<=n; i++) {if(i == a || i == b || i == c || i == d) continue;printf("%d ",i); }printf("%d %d\n",d,b);printf("%d %d ",c,a);for(int i = 1; i<=n; i++) {if(i == a || i == b || i == c || i == d) continue;printf("%d ",i); }printf("%d %d\n",b,d);return 0 ;
}

【CodeForces - 673D】Bear and Two Paths(构造,tricks)相关推荐

  1. Codeforces 673D Bear and Two Paths (贪心构造)

    题意 给出n个点,给出a,b,c,d,求能不能用少于m的边构成两条欧拉路 一条从a开始到b一条从c开始到d. 思路 因为m只有上限没有下限,我们贪心的构造就可以了,也就是说除了a,b,c,d其他的点都 ...

  2. CodeForces 658C Bear and Forgotten Tree 3(构造)

    题意:构造一棵树,有N个点,直径为d,深度为h 思路:首先构造一个长度为d的链,然后把其中一个距离边上为h的点变为根.然后我们就不停的在距离根为h上面的那一点不停的加点就好了,使得新加入的点的距离也为 ...

  3. 【CodeForces - 674B 】Bear and Two Paths(贪心,思维,水题)

    题干: 第一行给出N和M代表有N个难度1~N的题目,M代表有M个约束.接下来M行,每行两个数代表这一个约束的两个题目. 代表难度的数字越大,题目越难.现在要求你将N个题目分成不重不漏的两组(div1和 ...

  4. Codeforces 610C:Harmony Analysis(构造)

    [题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样 ...

  5. Codeforces 1276C/1277F/1259F Beautiful Rectangle (构造)

    题目链接 http://codeforces.com/contest/1276/problem/C 题解 嗯,比赛结束前3min想到做法然后rush不出来了--比赛结束后又写了15min才过-- 以下 ...

  6. CodeForces - 1504C Balance the Bits(思维+构造)

    题目链接:https://vjudge.net/problem/CodeForces-1504C 题目大意:给出一个长度为 nnn 的 010101 串,现在要求构造出两个长度为 nnn 的合法括号序 ...

  7. Codeforces 1492D - Genius‘s Gambit (构造)

    Codeforces Round #704 (Div. 2) D. Genius's Gambit 题意 要求构造出两个不包含前导0的二进制数字 x , y x,y x,y,满足: x , y x,y ...

  8. Codeforces 540B School Marks 【贪心构造】

    题目链接:Codeforces 540B School Marks Little Vova studies programming in an elite school. Vova and his c ...

  9. CodeForces - 1332 D. Walk on Matrix 构造

    CodeForces - 1332 D. Walk on Matrix 题目地址: http://codeforces.com/contest/1332/problem/D 基本题意: 给出上面这个动 ...

最新文章

  1. 27.5. PROCEDURE ANALYSE()
  2. 通用双谐振固态特斯拉驱动器 UD2.7
  3. Keystone controller.py routers.py代码解析
  4. SpringCloud 定义Eureka服务端、Eureka服务信息、Eureka发现管理、Eureka安全配置、Eureka-HA机制、 Eureka服务打包部署
  5. Swift--数组和字典(一)
  6. java8 默认方法_Java 8的默认方法:可以做什么和不能做什么?
  7. 单片机、ARM、DSP与CPU之间的关系大揭秘
  8. Asterisk 1.4.42将成绝唱
  9. Java—抽象类和接口的区别
  10. poi生成word不可以修改_操作不懂技术就可以做小程序无限生成平台的创业项目实操教程...
  11. Ajax之跨域访问与JSONP
  12. 虚拟系统管理VSM提高服务器整合率
  13. [Android] AudioEffect架构:从上层调用到底层音效驱动
  14. LightOJ-1054 Efficient Pseudo Code
  15. 期末复习-选择题整理(湖南大学操作系统课程雨课堂答案即期末题库)
  16. EXCEL的字符串处理公式,自带工作表函数汇总
  17. 第三篇: DDcGAN-用于多分辨率图像融合的双判别器生成对抗网络
  18. Pycharm安装教程 (2022最新版)
  19. EasyOcr报错 --- [WinError 10054] An existing connection was forcibly closed by the remote host
  20. Matlab在线性代数中的应用(三):求解非齐次线性方程组

热门文章

  1. [转]Win7 系统安装VS2008没反应 点击安装一闪就没有反应 .
  2. 随手小记·080911
  3. linux不支持32,Visual Studio Code 1.36发布,不再支持Linux 32位
  4. python权重初始值设置_pytorch自定义初始化权重的方法
  5. phpstudy(自己电脑主机做服务器,手机网站界面打不开)
  6. 505B. Mr. Kitayuta‘s Colorful Graph
  7. 人形图案c语言程序_最多 280 字符,你能用 Basic 玩出哪些花样程序来?
  8. iphone彻底删除照片如何恢复_手机删除的照片如何恢复?OPPO最新照片恢复
  9. 计算机如何用vb文本加密,信息加密与隐藏工具的设计与实现VB231
  10. datetimepicker不可以选择当天之前_专访吴京:网上《战狼3》的消息我都不知道,大家可以选择不信...