|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|0.7 초||512 MB||25||0||0||0.000%|
Santa has a Christmas Tree. In computer science terms, a Christmas Tree is a tree with N nodes where each node has a colour. Initially, all nodes have colour 0. One night, an elf comes (we call him Elf) to paint the tree because he found it very boring. M consecutive updates were performed on the given tree the following way: on update number X, Elf opens gift number X before Christmas (of course, it’s someone else’s gift) and finds a triplet (C, A, B) in it. After that, he paints with colour C all the nodes which can be found on the chain formed by vertices A and B. All colours are different from gift to gift, so we can assume that the M colours are M distinct values from 1 to M. While performing update X, some nodes may already be painted, in which case they will just be repainted with the new colour (the old one is lost forever :( )
Unfortunately, we do not know the M operations (the triplets found in the gifts), but we do know how the tree looks like in the end (you are given the colour of each node after performing all updates). Your task is to find a possible solution for the generated final form of the tree. More precisely, you have to find M triplets (in the correct order), such that if Elf would have found them in the gifts, he would obtain the Christmas Tree described in the input. Since there can be multiple solutions, you can display any of them.
6 3 1 3 2 1 1 2 1 4 2 4 3 4 4 5 5 6
2 6 3 1 5 1 3 2 2
5 3 3 2 1 2 1 1 2 1 3 1 4 4 5
1 3 5 2 2 4 3 1 1