Codeforces Round 351 (VK Cup 2016 Round 3, Div. 2 Edition)
D
Bear and Two Paths
Codeforces
未评级
原题
← CE →
翻译中…

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 $*v*_{1}, *v*_{2}, ..., *v*_{*n*}$ that $*v*_{1} = *a*$, $*v*_{*n*} = *b*$ and there is a road between $*v*_{*i*}$ and $*v*_{*i* + 1}$ for image.
翻译中…

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 $*u*_{1}, *u*_{2}, ..., *u*_{*n*}$ that $*u*_{1} = *c*$, $*u*_{*n*} = *d*$ and there is a road between $*u*_{*i*}$ and $*u*_{*i* + 1}$ for image.

翻译中…

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 $(*v*_{1}, ..., *v*_{*n*})$ and $(*u*_{1}, ..., *u*_{*n*})$ 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* ≤ 2*n* - 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 $*v*_{1}, *v*_{2}, ..., *v*_{*n*}$ where $*v*_{1} = *a*$ and $*v*_{*n*} = *b*$. The second line should contain $*n*$ distinct integers $*u*_{1}, *u*_{2}, ..., *u*_{*n*}$ where $*u*_{1} = *c*$ and $*u*_{*n*} = *d*$.

翻译中…

Two paths generate at most $2*n* - 2$ roads: $(*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 $*k*$ distinct roads or any other condition breaks. Note that $(*x*, *y*)$ and $(*y*, *x*)$ are the same road.

翻译中…

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$.

翻译中…

image

翻译中…

样例

Input #1
7 11
2 4 7 3
Output #1
2 7 1 3 6 5 4
7 1 5 4 6 2 3
InputCopy OutputCopy
Input #2
1000 999
10 20 30 40
Output #2
-1
InputCopy OutputCopy
题目信息
题号
673D
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。