Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths

题意:给定n个顶点和k条边。 还有4个点,a b c d要求找出一个图包括n个点和不超过k条边。并且输出一条路径从a->...->b   另一条路径从c->....->d,并且每条路径要都经过所以顶点一次并且仅一次。 不存在这样的路径输出-1

思路:模拟写几组数据可以发现当n=4或者n>=k时不存在这样的图。其他情况都满足。 对于a->..->b的路径: a->c->[其他非a b c d的点]->d->b  . 对于c->..->d的路径:c->a->[其他非a b c d的点]->b->d。 因为同时满足这2个路径的要求至少有n+1条边。

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<functional>  
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack> 
#include<bitset>
#include<vector> 
#include<algorithm>
using namespace std; 
const int MAXN=5000+5;
#define INF 0x3f3f3f3f
typedef long long int LL;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		if(n==4||k<=n){
			printf("-1\n");
		}
		else{
			printf("%d %d ",a,c);
			for(int i=1;i<=n;i++){
				if(!(i==a||i==b||i==c||i==d)){
					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)){
					printf("%d ",i);
				}
			}
			printf("%d %d\n",b,d);
		}
	}	
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值