CF643B.Bear and Two Paths

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bearland has nn cities, numbered 11 through nn . 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 aa and he wanted to go to a city bb . There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:

  • There is no road between aa and bb .
  • There exists a sequence (path) of nn distinct cities v1,v2,...,vnv_{1},v_{2},...,v_{n} that v1=av_{1}=a , vn=bv_{n}=b and there is a road between viv_{i} and vi+1v_{i+1} for .

On the other day, the similar thing happened. Limak wanted to travel between a city cc and a city dd . There is no road between them but there exists a sequence of nn distinct cities u1,u2,...,unu_{1},u_{2},...,u_{n} that u1=cu_{1}=c , un=du_{n}=d and there is a road between uiu_{i} and ui+1u_{i+1} for .

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

Given nn , kk and four distinct cities aa , bb , cc , dd , can you find possible paths (v1,...,vn)(v_{1},...,v_{n}) and (u1,...,un)(u_{1},...,u_{n}) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.

输入格式

The first line of the input contains two integers nn and kk ( 4<=n<=10004<=n<=1000 , n1<=k<=2n2n-1<=k<=2n-2 ) — the number of cities and the maximum allowed number of roads, respectively.

The second line contains four distinct integers aa , bb , cc and dd ( 1<=a,b,c,d<=n1<=a,b,c,d<=n ).

输出格式

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 nn distinct integers v1,v2,...,vnv_{1},v_{2},...,v_{n} where v1=av_{1}=a and vn=bv_{n}=b . The second line should contain nn distinct integers u1,u2,...,unu_{1},u_{2},...,u_{n} where u1=cu_{1}=c and un=du_{n}=d .

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

输入输出样例

  • 输入#1

    7 11
    2 4 7 3
    

    输出#1

    2 7 1 3 6 5 4
    7 1 5 4 6 2 3
    
  • 输入#2

    1000 999
    10 20 30 40
    

    输出#2

    -1
    

说明/提示

In the first sample test, there should be 77 cities and at most 1111 roads. The provided sample solution generates 1010 roads, as in the drawing. You can also see a simple path of length nn between 22 and 44 , and a path between 77 and 33 .

首页