码迷,mamicode.com
首页 > 其他好文 > 详细

ural 1339. Babies

时间:2015-11-26 22:49:02      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

1339. Babies

Time limit: 1.0 second
Memory limit: 64 MB
O tempora! O mores!
Present-day babies progress quickly. There are exactly k boys and k girls in the kindergarten. Some boys like some girls. But in this age the boys are still knights, so, if some boy like some girl then he likes the only girl and moreover one and the same girl can’t be liked by more than one boy. And the girls in this age are true ladies. So, if a girl likes a boy she likes the only one, and different girls like different boys.
The children are ingenuous. Their secret amorousness is well-known to the nurse. Once the group decided to go for a walk and the nurse made up her mind to fall the children in pairs so that if there is a boy or a girl in love in a pair then the boy likes his pair-mate or the girl likes the boy. Help the nurse to arrange the described pairs. You may assume that either the boys or the girls enumerated with positive integers from 1 to k.

Input

The first line contains the integer k — the number of boys (1 ≤ k ≤ 250 000). The second line consists of the numbers of girls that are liked by boys: if the i‘th boy likes some girls, her number is at the i‘th position; if the i‘th boy likes nobody, there is 0 at the i‘th position. The numbers are separated with a space. The third line consists of the analogous information about the girls.

Output

You should output the sequence of k integers. The i‘th element of the sequence is the number of a girl that is a pair-mate of the i‘th boy. The numbers are separated with a space.

Sample

inputoutput
3
3 0 0
0 2 0
3 2 1
Problem Author: Magaz Asanov
Problem Source: USU Championship 2004

ural 1339. Babies

标签:

原文地址:http://www.cnblogs.com/StupidBoy/p/4999138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!