Making a Necklace
Time limit1sMemory limit1024 MB
Given two graphs that each form a cycle with trees hanging off it, decide whether they are isomorphic and print the verdict.
- Level
Medium6 of 10
- Topics
- Graph, Tree, String matching
- Solved
- No attempts yet
Problem
Changhyun was bothered by the many couples at school, so he decided to confess to Minjun, whom he had liked for a while.
Minjun likes material gifts, so Changhyun decided to make a necklace and give it to her as a present when he confesses. Changhyun has a necklace made of threads and beads. Number the beads from 1 to in some order. For every pair of integers , with and , bead and bead are guaranteed to be connected by one thread. Minjun likes flashy gifts, so Changhyun decided to decorate the necklace with threads and beads.
First, Changhyun connects fewer than 30 beads with threads to make at most ornaments. An ornament has one more bead than it has threads. After making an ornament, Changhyun connects one bead of the ornament and one bead of the original necklace with a single thread. He repeats this until every ornament is attached to the original necklace. He does not attach two or more ornaments to the same bead, and he does not attach an ornament to a bead that was not part of the necklace before that ornament was attached.
Input
The day of the confession finally came, and Changhyun brought the necklace to Minjun. But he then realized a big problem: Minjun was wearing a necklace identical to the one he had made. Changhyun immediately decided to make a new necklace.
Changhyun wants to check whether the new necklace is the same as the old one. Given two necklaces, write a program that determines whether they are the same.
Two decorated necklaces and are the same if the following holds. Number the beads of and appropriately. For any two numbers with , bead and bead are connected by one thread in if and only if bead and bead are connected by one thread in .
Output
The first line contains and , separated by a space.
From the second line onward, the next lines each contain and , in that order. This means that bead and bead are connected by a thread in the old necklace.
From line onward, the next lines each contain and , in that order. This means that bead and bead are connected by a thread in the new necklace.
Constraints
If the two necklaces are different, print Go to Minjun. If they are the same, print Retry.
Hint
The time limit is 1000 ms and the memory limit is 1024 MB.