Tree Isomorphism | 프로그래밍의 벗 PivotOJ
PivotOJ

Tree Isomorphism

시간 제한: 1000ms메모리 제한: 1024MB출처: EIO 2018-19 finalBOJ 29949

문제

Today's assignment in art class was drawing labeled trees. To draw a labeled tree you first draw the integers 0N10 \ldots N-1 on a sheet of paper and then connect them by drawing N1N-1 lines between some pairs of them. The lines must be drawn so that it is possible to get from any integer to any other by following the lines.

Two pupils drew trees with the exact same number of integers, which made the teacher suspect plagiarism. Namely, she thinks that one student copied the other's tree and just changed some of the integers, leaving the lines as is.

Write a program that, given two trees of size NN, will print whether it is possible to turn the first tree into the second one by changing some (possibly none or all) integers. If it is possible, then it must also print the changes.

입력

The first line of input contains NN---the number of integers in each tree (1N1000001 \le N \le 100\,000). Each of the next N1N-1 lines contains two integers ss and tt which signify that the first tree has a line between integers ss and tt (0s<t<N0 \le s < t < N). Similarly, each of the following N1N-1 lines contains two integers uu and vv which signify that the second tree has a line between integers uu and vv (0u<v<N0 \le u < v < N).

출력

The first line of output must contain EI if it is not possible to turn the first tree into the second. Otherwise, the first line must contain JAH and each of the following NN lines must contain one integer pip_i, which signifies that the integer ii in the first tree must be changed into pip_i.

예제

예제 1

입력
5
0 3
3 4
2 4
1 4
3 4
0 2
1 3
0 3
출력
JAH
2
1
4
0
3

예제 2

입력
4
0 1
0 2
0 3
0 1
0 2
1 3
출력
EI
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.