CF1152E.Neko and Flashback

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A permutation of length kk is a sequence of kk integers from 11 to kk containing each integer exactly once. For example, the sequence [3,1,2][3, 1, 2] is a permutation of length 33 .

When Neko was five, he thought of an array aa of nn positive integers and a permutation pp of length n1n - 1 . Then, he performed the following:

  • Constructed an array bb of length n1n-1 , where bi=min(ai,ai+1)b_i = \min(a_i, a_{i+1}) .
  • Constructed an array cc of length n1n-1 , where ci=max(ai,ai+1)c_i = \max(a_i, a_{i+1}) .
  • Constructed an array bb' of length n1n-1 , where bi=bpib'_i = b_{p_i} .
  • Constructed an array cc' of length n1n-1 , where ci=cpic'_i = c_{p_i} .

For example, if the array aa was [3,4,6,5,7][3, 4, 6, 5, 7] and permutation pp was [2,4,1,3][2, 4, 1, 3] , then Neko would have constructed the following arrays:

  • b=[3,4,5,5]b = [3, 4, 5, 5]
  • c=[4,6,6,7]c = [4, 6, 6, 7]
  • b=[4,5,3,5]b' = [4, 5, 3, 5]
  • c=[6,7,4,6]c' = [6, 7, 4, 6]

Then, he wrote two arrays bb' and cc' on a piece of paper and forgot about it. 14 years later, when he was cleaning up his room, he discovered this old piece of paper with two arrays bb' and cc' written on it. However he can't remember the array aa and permutation pp he used.

In case Neko made a mistake and there is no array aa and permutation pp resulting in such bb' and cc' , print -1. Otherwise, help him recover any possible array aa .

输入格式

The first line contains an integer nn ( 2n1052 \leq n \leq 10^5 ) — the number of elements in array aa .

The second line contains n1n-1 integers b1,b2,,bn1b'_1, b'_2, \ldots, b'_{n-1} ( 1bi1091 \leq b'_i \leq 10^9 ).

The third line contains n1n-1 integers c1,c2,,cn1c'_1, c'_2, \ldots, c'_{n-1} ( 1ci1091 \leq c'_i \leq 10^9 ).

输出格式

If Neko made a mistake and there is no array aa and a permutation pp leading to the bb' and cc' , print -1. Otherwise, print nn positive integers aia_i ( 1ai1091 \le a_i \le 10^9 ), denoting the elements of the array aa .

If there are multiple possible solutions, print any of them.

输入输出样例

  • 输入#1

    5
    4 5 3 5
    6 7 4 6
    

    输出#1

    3 4 6 5 7 
    
  • 输入#2

    3
    2 4
    3 2
    

    输出#2

    -1
    
  • 输入#3

    8
    2 3 1 1 2 4 3
    3 4 4 2 5 5 4
    

    输出#3

    3 4 5 2 1 4 3 2 
    

说明/提示

The first example is explained is the problem statement.

In the third example, for a=[3,4,5,2,1,4,3,2]a = [3, 4, 5, 2, 1, 4, 3, 2] , a possible permutation pp is [7,1,5,4,3,2,6][7, 1, 5, 4, 3, 2, 6] . In that case, Neko would have constructed the following arrays:

  • b=[3,4,2,1,1,3,2]b = [3, 4, 2, 1, 1, 3, 2]
  • c=[4,5,5,2,4,4,3]c = [4, 5, 5, 2, 4, 4, 3]
  • b=[2,3,1,1,2,4,3]b' = [2, 3, 1, 1, 2, 4, 3]
  • c=[3,4,4,2,5,5,4]c' = [3, 4, 4, 2, 5, 5, 4]
首页