Tree Isomorphism
시간 제한1초메모리 제한1024 MB
두 개의 트리가 주어질 때, 첫 번째 트리의 정수 이름을 바꾸어 두 번째 트리와 정확히 일치하게 만들 수 있는지 판정하고, 가능하면 그 이름 변경을 출력하는 문제다. 트리의 동형성(isomorphism)을 판정하고 구체적인 대응을 구성해야 한다.
문제
Today's assignment in art class was drawing labeled trees. To draw a labeled tree you first draw the integers on a sheet of paper and then connect them by drawing 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 , 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 ---the number of integers in each tree (). Each of the next lines contains two integers and which signify that the first tree has a line between integers and (). Similarly, each of the following lines contains two integers and which signify that the second tree has a line between integers and ().
출력
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 lines must contain one integer , which signifies that the integer in the first tree must be changed into .