看样例然后发现只要求一个一笔画即可,用板子。

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. using namespace std;
  7. const int maxn = 1e5 + 5;
  8. int n, b[maxn], c[maxn], _b[maxn], _c[maxn];
  9. int d[maxn << 1], tot;
  10. vector<pair<int, int>> adj[maxn << 1];
  11. bool vis[maxn];
  12. int ans[maxn];
  13. int cnt;
  14. void dfs(int cur) {
  15. while (!adj[cur].empty()) {
  16. auto tmp = adj[cur].back();
  17. adj[cur].pop_back();
  18. if (!vis[tmp.second]) {
  19. vis[tmp.second] = 1;
  20. dfs(tmp.first);
  21. ans[cnt++] = tmp.first;
  22. }
  23. }
  24. }
  25. int main() {
  26. scanf("%d", &n);
  27. for (int i = 1; i < n; i++)
  28. scanf("%d", &b[i]), d[++tot] = b[i];
  29. for (int i = 1; i < n; i++)
  30. scanf("%d", &c[i]), d[++tot] = c[i];
  31. sort(d + 1, d + 1 + tot);
  32. tot = unique(d + 1, d + 1 + tot) - d - 1;
  33. for (int i = 1; i < n; i++) {
  34. _b[i] = lower_bound(d + 1, d + 1 + tot, b[i]) - d;
  35. _c[i] = lower_bound(d + 1, d + 1 + tot, c[i]) - d;
  36. if (_b[i] > _c[i]) {
  37. puts("-1");
  38. return 0;
  39. }
  40. adj[_b[i]].push_back({_c[i], i});
  41. adj[_c[i]].push_back({_b[i], i});
  42. }
  43. vector<int> v;
  44. for (int i = 1; i <= tot; i++) {
  45. if (adj[i].size() % 2 == 1)
  46. v.push_back(i);
  47. }
  48. if (v.size() == 2) {
  49. dfs(v[0]);
  50. ans[cnt++] = v[0];
  51. } else if(v.size() == 0) {
  52. dfs(1);
  53. ans[cnt++] = 1;
  54. }
  55. if (cnt == n)
  56. for (int i = cnt - 1; ~i; --i)
  57. printf("%d ", d[ans[i]]);
  58. else puts("-1");
  59. return 0;
  60. }

Codeforces 1152E(欧拉路径)的更多相关文章

  1. CodeForces 1152E Neko and Flashback

    题目链接:http://codeforces.com/problemset/problem/1152/E 题目大意 有一个 1~n-1 的排列p 和长度为 n 的数组 a,数组b,c定义如下: b:b ...

  2. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  3. Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径

    E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...

  4. Codeforces Round #554 (Div. 2) E Neko and Flashback (欧拉路径 邻接表实现(当前弧优化..))

    就是一欧拉路径 贴出邻接表欧拉路径 CODE #include <bits/stdc++.h> using namespace std; const int MAXN = 100005; ...

  5. Codeforces Round 1152 (div. 2)

    奇差.ABC三题,排名400. 首先是策略问题. 由于第一眼看到D的时候感觉不太会做,于是去看E. 一看到E这不欧拉回路吗,可做可做, 于是--我不会欧拉回路! 手推.推了半天啥也没弄出来, 于是大概 ...

  6. 【题解】Weird journey Codeforces 788B 欧拉路

    传送门:http://codeforces.com/contest/788/problem/B 好题!好题! 首先图不连通的时候肯定答案是0,我们下面讨论图联通的情况 首先考虑,如果我们每条边都经过两 ...

  7. 【codeforces 723E】One-Way Reform

    [题目链接]:http://codeforces.com/contest/723/problem/E [题意] 给你一个无向图; 让你把这m条边改成有向图; 然后使得出度数目等于入度数目的点的数目最多 ...

  8. 【codeforces 508D】Tanya and Password

    [题目链接]:http://codeforces.com/problemset/problem/508/D [题意] 给你一个字符的所有连续3个的子串; 让你复原出原串; (包含小写.大写字母以及数字 ...

  9. Educational Codeforces Round 85 (Div. 2)

    题目链接:https://codeforces.com/contest/1334 A. Level Statistics 题意 一个关卡有玩家的尝试次数和通关次数,按时间顺序给出一个玩家 $n$ 个时 ...

随机推荐

  1. html5--1.19 通用属性

    html5--1.19 通用属性 学习要点: 1.通用属性的概念及几个常用的通用属性2.对属性值的若干点补充 通用属性 通用属性(全局属性)可以用于任何的HTML5元素:通用属性有十几种:这节课不会全 ...

  2. 如何改变cmd窗口大小

      按下Win+R(windows徽标和R一起按),再输入cmd. 输入mode ,查看当前屏幕的大小,来为后面准备(大概估计数值大小). 再输入mode con:cols=400 lines=400 ...

  3. Java_正则_00_资源贴

    二.参考资料 1.揭开正则表达式的神秘面纱

  4. 1076 Forwards on Weibo (30)(30 分)

    Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may ...

  5. 描述怎样通过flask+redis+sqlalchemy等工具,开发restful api

    flask开发restful api系列(8)-再谈项目结构 摘要: 进一步介绍flask的项目结构,使整个项目结构一目了然.阅读全文 posted @ 2016-06-06 13:54 月儿弯弯02 ...

  6. 单机 Oracle 11g(11.2.0.4)手动打补丁PSU(11.2.0.4.8)

    环境说明:database : 11.2.0.4 x64os: centos6.7 x64 准备内容:OPatch : p6880880_112000_Linux-x86-64.zipDB PSU : ...

  7. bzoj 3073 [Pa2011]Journeys ——线段树优化连边

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3073 建两棵线段树,一棵孩子向父亲连边,是走出去的:一棵父亲向孩子连边,是走进来的. 注意第 ...

  8. Grunt:GruntFile.js

    ylbtech-Grunt:GruntFile.js 1.返回顶部 1. module.exports = function (grunt) { grunt.initConfig({ useminPr ...

  9. 五 Vue学习 首页学习 (上)

    首页:   http://localhost:8002/#/,  登录页面如下: index.js文件中如下的路由配置,转过去看login.vue是如何实现的. const routes = [ { ...

  10. Windows WMIC命令使用详解1

    https://blog.csdn.net/enweitech/article/details/51982114 在CMD和Powershell中 使用WMIC 先决条件: a. 启动Windows ...