题意

给出n个点,给出a,b,c,d,求能不能用少于m的边构成两条欧拉路
一条从a开始到b一条从c开始到d。

思路

因为m只有上限没有下限,我们贪心的构造就可以了,也就是说除了a,b,c,d其他的点都用相同的路径,这样就能使得路径最少了。
需要注意的是n等于4的时候。

代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define LL long long
#define lowbit(x) ((x)&(-x))
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1|1
#define MP(a, b) make_pair(a, b)
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const int maxn = 1e5 + 10;
const double eps = 1e-8;
const double PI = acos(-1.0);
typedef pair<int, int> pii;int main()
{//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int n, m, a, b, c, d;cin >> n >> m;cin >> a >> b >> c >> d;if (m < n - 1 + 2 || n == 4) return puts("-1");vector<int> v;for (int i = 1; i <= n; i++){if (i != a && i != b && i != c && i != d)v.push_back(i);}cout << a << " " << c << " ";for (int i = 0; i < v.size(); i++)cout << v[i] << " ";cout << d << " " << b << endl;cout << c << " " << a << " ";for (int i = 0; i < v.size(); i++)cout << v[i] << " ";cout << b << " " << d << endl;return 0;
}

Codeforces 673D Bear and Two Paths (贪心构造)相关推荐

  1. 【CodeForces - 673D】Bear and Two Paths(构造,tricks)

    题干: Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each ...

  2. CodeForces - 1364C Ehab and Prefix MEX(贪心+构造)

    题目链接:点击查看 题目大意:给出一个数组 a ,要求构造一个数组 b ,使得 a[ i ] = MEX{ b[ 1 ] , b[ 2 ] , ... b[ i - 1 ] , b[ i ] },a[ ...

  3. CodeForces 1610H Squid Game(延迟贪心 + 构造 + 树状数组)

    problem 洛谷链接 solution 考虑重新随便钦定一个点为"根",并且强制根必须是关键点. 则所有 x−yx-yx−y 不是直系祖先-子代的要求(要求Ⅰ),即 xxx 不 ...

  4. 【CodeForces - 746E】Numbers Exchange(贪心构造)

    题干: Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange ...

  5. 贪心+构造 Codeforces Round #277 (Div. 2) C. Palindrome Transformation

    题目传送门 1 /* 2 贪心+构造:因为是对称的,可以全都左一半考虑,过程很简单,但是能想到就很难了 3 */ 4 /**************************************** ...

  6. 【VK Cup 2016 - Round 1 (Div 2 Edition)C】【构造】Bear and Forgotten Tree 3 构造一棵树直径为d且点1的深度为h

    Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  7. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  8. 2021年度训练联盟热身训练赛第五场 H题In-place Sorting+贪心构造

    题意: 给你n个小于101810^{18}1018的大数,问在可以再不改变序列位置,之改变数值中某数位的'9'变为'6'或将'6'变为'9',求的最终序列由小到大,且字典序最小. 题目: 链接:htt ...

  9. 【牛客 - 318G】LLLYYY的数字思维 与【牛客 - 289J】这是一个沙雕题II(贪心构造)

    题干: LLLYYY很喜欢写暴力模拟贪心思维.某一天在机房,他突然抛给了队友ppq一 个问题.问题如下: 有一个函数f (): int f(int x){     int tmp = 0;     w ...

最新文章

  1. MySql: 常见错误
  2. Acwing第 11 场周赛【未完结】
  3. React-Native视频组件react-native-video使用(安卓版)
  4. 视频剪辑什么鬼?Python 带你高效创作短视频
  5. 正则表达式只能写数字_正则表达式真的很骚,可惜你不会写
  6. realme下月将推Q3s:Q系列下半年独苗 配置更强更全面
  7. Flink 1.9 写入HDFS报错 UnsupportedFileSystemSchemeException:hdfs
  8. Java多线程学习九:如何正确关闭线程池?shutdown 和 shutdownNow 的区别
  9. android谷歌反地理,android – 谷歌地理编码服务是不可用的(协调地址)
  10. 万物皆可Graph | 当推荐系统遇上图神经网络(四)
  11. 一文读完C语言基础语法
  12. linux制作iso启动盘
  13. WPE封包外挂教程(上)
  14. mapboxgl 互联网地图纠偏插件(二)
  15. HAUT OJ 1504: CXK的篮球数(加强版)--差分法
  16. private111
  17. 塔科夫服务器修改器,逃离塔科夫修改器+15项
  18. 《Photoshop修饰与合成专业技法》—第1章伪造的抠像:第一部分
  19. 为什么你还没有买新能源汽车? 1
  20. Android Studio课堂总结05

热门文章

  1. matlab中整流器怎么用,Simscape Electrical
  2. [CS231n Assignment 3 #03] 网络可视化:显著映射、类可视化和欺骗图像
  3. zeronet使用指南
  4. photoshop里上色之后,颜色总是灰色的,解决办法
  5. 《摔跤吧!爸爸》中引人深思的中英文台词
  6. 小福利,如何用python解方程
  7. 公司公司代码业务范围成本控制范围概念
  8. python scapy实现ARP欺骗与DNS欺骗
  9. win10 jdk环境配置
  10. 项目管理中的放弃艺术