Telepathy
시간 제한2초메모리 제한2048 MB
같은 나무를 서로 다른 이름으로 표시한 지도를 가진 두 사람이 대화 없이 각자 이동 경로를 정해 6d턴 안에 같은 지점에서 만나야 한다.
문제
Aitana and Bruno are visiting a national park in Bolivia. In the national park, there are sites, and there are roads connecting two sites. It is possible to move from any site to any site by passing through some roads.
When they were walking in the national park, they got separated from each other. From now on they must meet again by reaching the same site at the same time. However, being deep in the Amazon rainforest, they cannot communicate with each other. The only thing they can rely on is their own map, which depicts the road structure of the national park. Each of them wrote labels for each site in his/her map. However, the labeling of Aitana and Bruno may be different.
Aitana and Bruno now start moving to meet again. For each turn, they simultaneously perform either of the following actions: move to the site that is directly connected by road to the current site, or stay at the current site.
Write a program that implements a strategy to make Aitana and Bruno meet again. In this problem, a submission receives the full score if they meet again within turns, where is the minimum number of roads to pass to move from Aitana’s current site to Bruno’s current site. Note that, when they come to the same place in the middle of the road, it is not considered that they meet again.
In this problem, one must solve for scenarios in a single run of the program.
Problem Details
In this section, we formally explain the problem. Each site of the national park is assigned an ID from to , and the -th road () connects the site with ID and ID . For the site with ID (), label is written on Aitana’s map, and label is written on Bruno’s map. Here, and are permutations of .
Aitana knows that, for each , there is a road connecting the sites labeled and , and Aitana is currently at the site labeled . The “label” here is based on the Aitana’s map. Hence, the -th road () connects the sites labeled and label , and holds where is the ID of Aitana’s current site. However, the roads may not be given in the order, and the two sites that each road connects may not be given in the order of , . Similarly, Bruno knows that, for each , there is a road connecting the sites labeled and , and Bruno is currently at the site labeled . The “label” here is based on the Bruno’s map. Especially, holds where is the ID of Bruno’s current site.
Based on the information above, Aitana and Bruno decide their movement of the next turns. In other words, Aitana decides the sequence of labels , and Bruno decides the sequence of labels , which represents his/her movement, independently. They must satisfy the following conditions:
- , and for each (), the sites labeled and in Aitana’s map are either the same site or directly connected by a road.
- , and for each (), the sites labeled and in Bruno’s map are either the same site or directly connected by a road.
The turn number when Aitana and Bruno meet again is the minimum such that label (in Aitana’s map) and label (in Bruno’s map) represent the same site. A submission receives the full score if .
제한
In this problem, you need to solve the problem for at most scenarios, that is, . Each scenario satisfies the following constraints.
- .
- is the permutation of the integers between and (inclusive).
- is the permutation of the integers between and (inclusive).
- ().
- ().
- It is possible to move from any site to any site by passing through some roads.
- .
- .
- .
예제
이 문제는 공개된 예제가 없습니다.