VK Cup 2016 D. Bear and Two Paths 模拟
2 seconds
256 megabytes
standard input
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.
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).
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, ..., unwhere 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.
7 11
2 4 7 3
2 7 1 3 6 5 4
7 1 5 4 6 2 3
1000 999
10 20 30 40
-1
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.
题目链接:http://codeforces.com/contest/673/problem/D
题意:n个点,m条边的一个图。是否有一条a到b,一条c到d的路径,这两条路径经过所有的点,并且a不能直接到达b,c不能直接到达d。存在这样的图输出两条路径,不存在就输出-1。
思路:
如图所示,构造图。边的数目至少为n+1。当n为4时不符合情况。
代码:
#include <bits/stdc++.h>
using namespace std;
int sign[];
int main()
{
int i,n,k;
int a,b,c,d;
int gg;
memset(sign,,sizeof(sign));
cin>>n>>k;
cin>>a>>b>>c>>d;
sign[a]=sign[b]=sign[c]=sign[d]=;
if(n==) cout<<"-1"<<endl;
else if(k>=n+)
{
for(i=; i<=n; i++)
if(sign[i]==)
{
gg=i;
sign[gg]=;
break;
}
cout<<a<<" ";
for(i=; i<=n; i++)
if(sign[i]==) cout<<i<<" ";
cout<<c<<" "<<gg<<" "<<d<<" "<<b<<endl;
cout<<c<<" ";
for(i=n; i>=; i--)
if(sign[i]==) cout<<i<<" ";
cout<<a<<" "<<gg<<" "<<b<<" "<<d<<endl;
}
else cout<<"-1"<<endl;
return ;
}
VK Cup 2016 D. Bear and Two Paths 模拟的更多相关文章
- 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 ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D
D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D Bear and Two Paths
题目链接: http://codeforces.com/contest/673/problem/D 题意: 给四个不同点a,b,c,d,求是否能构造出两条哈密顿通路,一条a到b,一条c到d. 题解: ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3
C. Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C. Bear and Colors 暴力
C. Bear and Colors 题目连接: http://www.codeforces.com/contest/673/problem/C Description Bear Limak has ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) A. Bear and Game 水题
A. Bear and Game 题目连接: http://www.codeforces.com/contest/673/problem/A Description Bear Limak likes ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) E. Bear and Contribution 单调队列
E. Bear and Contribution 题目连接: http://www.codeforces.com/contest/658/problem/E Description Codeforce ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) D. Bear and Polynomials
D. Bear and Polynomials 题目连接: http://www.codeforces.com/contest/658/problem/D Description Limak is a ...
- VK Cup 2016 - Round 1 (Div. 2 Edition) C. Bear and Forgotten Tree 3 构造
C. Bear and Forgotten Tree 3 题目连接: http://www.codeforces.com/contest/658/problem/C Description A tre ...
随机推荐
- jmeter建立JDBC连接池时遇到“A Test is currently running,stop or shutdown test to execute this command”
1.显示如下图,打开日志可以看到:Variable Name must not be empty for element:JDBC Connection Configuration,即JDBC Con ...
- python输入输出及变量
知识内容: 1.python输出及注释 2.变量及常量 3.python用户输入 4.Hello,World程序 一.python输出及注释 1.python输出 在python2和python3中的 ...
- drop解决过拟合的情况
用到的训练数据集:sklearn数据集 可视化工具:tensorboard,这儿记录了loss值(预测值与真实值的差值),通过loss值可以判断训练的结果与真实数据是否吻合 过拟合:训练过程中为了追求 ...
- php内存回收机制的学习
今天朋友去面试,回来问了一下怎么样,结果他说一脸懵逼,看来我们平时还是学习的太少了啊.于是比较好奇,果断问了一下都有哪些问题,朋友说第一个问题就是“描述PHP的垃圾回收机制”,我当时听了也是一脸茫然, ...
- python气象分析
数据分析实例 -- 气象数据 一.实验介绍 本实验将对意大利北部沿海地区的气象数据进行分析与可视化.我们在实验过程中先会运用 Python 中matplotlib库的对数据进行图表化处理,然后调用 s ...
- svn异常处理
TortoiseSVN 为客户端,SUBVersion为服务器端. 1.安装的tortoiseSVN不在鼠标右键菜单栏 出现这种原因是电脑的系统和svn不符,即电脑是64位系统,而svn是32位的. ...
- C#--Winform项目核心模块--考勤模块
C#--Winform项目核心模块--考勤模块(一) C#--Winform项目核心--考勤模块(二) C#--Winform项目核心模块--考勤模块(三)
- 行矩阵列矩阵D3D&GL&U3D
void Start () { //矩阵函数原型:Matrix4x4(Vector4 colum0, Vector4 colum1, Vector4 colum2, Vector4 colum3),这 ...
- C#累加器函数Aggregate用法 讲解
Enumerable.Aggregate 扩展方法在System.Linq命名空间中,是Enumerable类的第一个方法(按字母顺序排名),但确是Enumerable里面相对复杂的方法. MSDN对 ...
- SVM总结(转)
支持向量机 看了JULY君的博客和文档后,个人对SVM的理解和总结,欢迎交流和指正.其理论部分可以查看下面文档链接,通俗易懂. 支持向量机通俗导论(理解SVM的三层境界) 第一篇:从四个关键词 ...