문제
Farmer John's
First, due to the cows' social hierarchy, some cows insist on being milked before other cows, based on the social status level of each cow. For example, if cow 3 has the highest status, cow 2 has average status, and cow 5 has low status, then cow 3 would need to be milked earliest, followed later by cow 2 and finally by cow 5.
Second, some cows only allow themselves to be milked at a certain position within the ordering. For example, cow 4 might insist on being milked second among all the cows.
Luckily, Farmer John will always be able to milk his cows in an order satisfying all of these conditions.
Unfortunately, cow 1 has recently fallen ill, so Farmer John wants to milk this cow as early in the order as possible so that she can return to the barn and get some much-needed rest. Please help Farmer John determine the earliest position cow 1 can appear in the milking order.
[번역]
농부 존의
그 결과로 매일 아침 농부 존이 소젖을 짜면서 소들의 복잡한 사회 구조를 연구했다. 몇 주간의 연구 끝에 농부 존은 이 구조가 두 가지 핵심 속성에 기반한다는 것을 발견했다.
첫째로, 소들의 사회 계급 때문에 어떤 소들은 다른 소들보다 먼저 젖을 짜달라 요구한다. 각 소의 사회적 지위에 따라, 예를 들어 소 3이 가장 높은 지위를 가지고 있고 소 2가 평균 지위를 가지고 있으며 소 5가 낮은 지위를 가지고 있다면, 소 3이 가장 먼저 젖을 짜고 그 다음에 소 2가, 마지막으로 소 5가 젖을 짠다.
둘째로, 어떤 소들은 순서 상 특정 순서로만 젖을 짤 수 있다. 예를 들어, 소 4는 다른 소들 중에서 두 번째로만 젖을 짜야 한다고 주장할 수 있다.
다행히도, 농부 존은 항상 이러한 조건을 만족시키는 순서로 소젖을 짤 수 있다.
불행히도 소 1이 최근에 아파졌기 때문에, 농부 존은 이 소를 가능한 한 순서 상에서 가장 빨리 처리해줘 푹 쉴 수 있도록 하고 싶어한다.
농부 존을 도와 소 1의 순서 중 가능한 가장 빠른 순서를 출력하시오.
입력
The first line contains
It is guaranteed that under these constraints, Farmer John will be able to construct a valid milking order.
첫 번째 줄에 세 정수
다음 줄에는
그 다음
이러한 제약 조건 하에서 농부 존이 유효한 순서를 만들 수 있을 것이 보장된다.
출력
소 1의 순서 중 가능한 가장 빠른 순서를 출력한다.
예제
6 3 2
4 5 6
5 3
3 1
4
In this example, Farmer John has six cows, with cow 1 being sick. He needs to milk cow 4 before cow 5 and cow 5 before cow 6. Moreover, Farmer John has to milk cow 3 first and cow 5 third.
FJ has to milk cow 3 first, and since cow 4 has to come before cow 5, cow 4 must be milked second, and cow 5 third. Thus, cow 1 can be fourth at earliest in the order.
이 예시에서 농부 존은 여섯 마리의 소를 가지고 있으며, 소 1이 아플 때이다. 소 4를 소 5보다 먼저, 그리고 소 5를 소 6보다 먼저 처리해야 한다. 게다가 농부 존은 소 3을 먼저, 소 5를 세 번째로 처리해야 합니다.
농부 존은 먼저 소 3을, 그리고 소 4가 소 5보다 먼저 와야 하므로 소 4는 두 번째로 와야 한다. 그리고 소 5는 세 번째로 와야 한다. 따라서 소 1의 가장 빠른 순서는 네 번째이다.