codeforces 673D 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 题意: 给出n个节点,然后给出两条路线的起点和终点,要求你构造一个无向图,使无向图中a,b之间和c,d之间均无直接相连的边,且要求这个图的边的条数不超过k; 思路: 发现n==4时怎么都不可能满足;
可以构造这样的无向图
第一条路线ac...db; 第二条路线ca...bd;
这样的边是n+1条,是最少的了; AC代码:
#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e5+;
int n,k,a,b,c,d;
int vis[];
int main()
{
scanf("%d%d",&n,&k);
scanf("%d%d%d%d",&a,&b,&c,&d);
if(k<n+||n==)cout<<"-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); } return ;
}
codeforces 673D 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 ...
- D. Bear and Two Paths(贪心构造)
D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 ...
- [Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs)
[Codeforces 1005F]Berland and the Shortest Paths(最短路树+dfs) 题面 题意:给你一个无向图,1为起点,求生成树让起点到其他个点的距离最小,距离最小 ...
- 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. 题解: ...
- Codeforces 1144F Graph Without Long Directed Paths (DFS染色+构造)
<题目链接> 题目大意:给定一个无向图,该无向图不含自环,且无重边.现在要你将这个无向图定向,使得不存在任何一条路径长度大于等于2.然后根输入边的顺序,输出构造的有向图.如果构造的边与输入 ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
随机推荐
- unity的List构造函数在IOS平台存在缺陷
当迩使用一个int[]或者string[]类似的数组时,以数组来初始化List对象,有可能在IOS平台上会出现初始化对象为空,比如 , }; List<int> listTest = ne ...
- 让Mac OS X专用高速移动硬盘在Linux下也能被读写
MacBook Pro以及iMac等设备都具备雷电接口和USB 3.0接口,配合使用Mac OS X格式化的专用高速移动硬盘读写数据都非常快.那么这种硬盘可以在Linux下被读写吗?其实,Mac OS ...
- vba功能语句
VBA语句集(第1辑) 定制模块行为(1) Option Explicit '强制对模块内所有变量进行声明Option Private Module '标记模块为私有,仅对同一工程中其它模块有用,在宏 ...
- 如何选择 IT 技术书籍
★第1招:看网上评论 首先,上一些权威的图书网站,看看大伙儿的评价如何(要相信群众的眼睛是雪亮的).对于英文书籍,我一般上亚马逊网站去看看:中文书籍则上豆瓣网.这两个网站都提供星级评分,一般 > ...
- ASP.NETCore使用AutoFac依赖注入
原文:ASP.NETCore使用AutoFac依赖注入 实现代码 1.新建接口类:IRepository.cs,规范各个操作类的都有那些方法,方便管理. using System; using Sys ...
- HDU1800 Flying to the Mars 【贪心】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- keras函数式编程(多任务学习,共享网络层)
https://keras.io/zh/ https://keras.io/zh/getting-started/functional-api-guide/ https://github.com/ke ...
- jmeter - DBC Request之Query Type
工作中遇到这样一个问题: 需要准备10W条测试数据,利用jmeter中的JDBC Request向数据库中批量插入这些数据(只要主键不重复就可以,利用函数助手中的Random将主键的ID末尾五位数随机 ...
- 图片3d轮放查看效果(V2.0):使用鼠标拖动实现图片的轮放
上面的版本号为通过左右button实现图片轮放,这个版本号.是通过在窗体拖动鼠标.左右滑动图片. 关键点在于选择一个合适的值.使鼠标拖动时.全部图片均可显示,可是不会滑动过快或离开窗体. 不多说,直接 ...
- Win8下怎样安装Win7 or Win7下怎样安装win8?
预计非常多人可能会用U盘安装工具去去做双系统的安装(Win8下安装Win7, Win7下安装Win8).可是在安装过程中你 会发现一个问题:win7下安装win8,提示你mbr硬盘格式不能安装win8 ...