Logo
(追記) (追記ここまで)

11623번 - Kernel Knights 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB266937633.480%

문제

Jousting is a medieval contest that involves people on horseback trying to strike each other with wooden lances while riding at high speed. A total of 2n knights have entered a jousting tournament – n knights from each of the two great rival houses. Upon arrival, each knight has challenged a single knight from the other house to a duel.

A kernel is defined as some subset S of knights with the following two properties:

  • No knight in S was challenged by another knight in S.
  • Every knight not in S was challenged by some knight in S.

Given the set of the challenges issued, find one kernel. It is guaranteed that a kernel always exists.

입력

The first line contains an integer n (1 ≤ n ≤ 100 000) – the number of knights of each house. The knights from the first house are denoted with integers 1 through n, knights from the second house with integers n + 1 through 2n.

The following line contains integers f1, f2, . . . , fn – the k-th integer fk is the index of the knight challenged by knight k (n + 1 ≤ fk ≤ 2n).

The following line contains integers s1,s2, . . . ,sn – the k-th integer sk is the index of the knight challenged by knight n + k (1 ≤ sk ≤ n).

출력

Output the indices of the knights in the kernel on a single line. If there is more than one solution, you may output any one.

제한

예제 입력 1

4
5 6 7 7
1 3 2 3

예제 출력 1

1 2 4 8

힌트

출처

ICPC > Regionals > Europe > Central European Regional Contest > CERC 2015 K번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /