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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std; const int maxn = 1e5 + 5;
int n, b[maxn], c[maxn], _b[maxn], _c[maxn];
int d[maxn << 1], tot;
vector<pair<int, int>> adj[maxn << 1];
bool vis[maxn];
int ans[maxn];
int cnt; void dfs(int cur) {
while (!adj[cur].empty()) {
auto tmp = adj[cur].back();
adj[cur].pop_back();
if (!vis[tmp.second]) {
vis[tmp.second] = 1;
dfs(tmp.first);
ans[cnt++] = tmp.first;
}
}
} int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++)
scanf("%d", &b[i]), d[++tot] = b[i];
for (int i = 1; i < n; i++)
scanf("%d", &c[i]), d[++tot] = c[i]; sort(d + 1, d + 1 + tot);
tot = unique(d + 1, d + 1 + tot) - d - 1;
for (int i = 1; i < n; i++) {
_b[i] = lower_bound(d + 1, d + 1 + tot, b[i]) - d;
_c[i] = lower_bound(d + 1, d + 1 + tot, c[i]) - d;
if (_b[i] > _c[i]) {
puts("-1");
return 0;
}
adj[_b[i]].push_back({_c[i], i});
adj[_c[i]].push_back({_b[i], i});
} vector<int> v;
for (int i = 1; i <= tot; i++) {
if (adj[i].size() % 2 == 1)
v.push_back(i);
}
if (v.size() == 2) {
dfs(v[0]);
ans[cnt++] = v[0];
} else if(v.size() == 0) {
dfs(1);
ans[cnt++] = 1;
}
if (cnt == n)
for (int i = cnt - 1; ~i; --i)
printf("%d ", d[ans[i]]);
else puts("-1");
return 0;
}

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. 谷歌新操作系统fuchsia

    开源地址: https://github.com/fuchsia-mirror

  2. BZOJ 2021 [Usaco2010 Jan]Cheese Towers:dp + 贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2021 题意: John要建一个奶酪塔,高度最大为m. 他有n种奶酪.第i种高度为h[i]( ...

  3. 分享知识-快乐自己: Oracle数据库实例、用户、表、表空间之间关系

    数据库: Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件). 其实Oracle数据库的概念和其它数据库不一样,这里的数据库是一个操作系统只有一个库 ...

  4. Git_学习_02_ 分支

    Git鼓励大量使用分支: 1.查看分支:git branch 2.创建分支:git branch <name> 3.切换分支:git checkout <name> 4.创建+ ...

  5. codeforces 569C C. Primes or Palindromes?(素数筛+dp)

    题目链接: C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes in ...

  6. 简单两步快速实现shiro的配置和使用,包含登录验证、角色验证、权限验证以及shiro登录注销流程(基于spring的方式,使用maven构建)

    前言: shiro因为其简单.可靠.实现方便而成为现在最常用的安全框架,那么这篇文章除了会用简洁明了的方式讲一下基于spring的shiro详细配置和登录注销功能使用之外,也会根据惯例在文章最后总结一 ...

  7. EMQ开启mysql认证

    规定通过mqtt_user表格验证过的用户才能连接EMQ服务器,我们需要开启mysql插件认证.EMQ2.0自带mysql插件,下面开始配置. 新建mqtt_user表格 要想控制用户登录EMQ,肯定 ...

  8. CF 438 E & bzoj 3625 小朋友和二叉树 —— 多项式开方

    题目:http://codeforces.com/contest/438/problem/E https://www.lydsy.com/JudgeOnline/problem.php?id=3625 ...

  9. BLE Mesh网络协议综述

    0 引言 自2012年蓝牙4.0规范推出之后,全新的蓝牙低功耗(BLE)技术由于其极低的运行和待机功耗.低成本和跨厂商互操作性,3 ms低延迟.AES-128加密等诸多特色,可以用于计步器.心律监视器 ...

  10. cookie,sessionStorage 和 localStorage

    1.三者之间的区别 cookie是网站为了标示用户身份而储存在用户本地终端(Client Side)上的数据(通常经过加密). cookie数据始终在同源的http请求中携带(即使不需要),记会在浏览 ...