Logo
(追記) (追記ここまで)

27011번 - Part Acquisition 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB46171540.541%

문제

The cows have been sent on a mission through space to acquire a new milking machine for their barn. They are flying through a cluster of stars containing N (1 ≤ N ≤ 50,000) planets, each with a trading post.

The cows have determined which of K (1 ≤ K ≤ 1,000) types of objects (numbered 1..K) each planet in the cluster desires, and which products they have to trade. No planet has developed currency, so they work under the barter system: all trades consist of each party trading exactly one object (presumably of different types).

The cows start from Earth with a canister of high quality hay (item 1), and they desire a new milking machine (item K). Help them find the best way to make a series of trades at the planets in the cluster to get item K. If this task is impossible, output -1.

입력

  • Line 1: Two space-separated integers, N and K.
  • Lines 2..N+1: Line i+1 contains two space-separated integers, a_i and b_i respectively, that are planet i's trading trading products. The planet will give item b_i in order to receive item a_i.

출력

  • Line 1: One more than the minimum number of trades to get the milking machine which is item K (or -1 if the cows cannot obtain item K).
  • Lines 2..T+1: The ordered list of the objects that the cows possess in the sequence of trades.

제한

예제 입력 1

6 5
1 3
3 2
2 3
3 1
2 5
5 4

예제 출력 1

4
1
3
2
5

힌트

The cows possess 4 objects in total: first they trade object 1 for object 3, then object 3 for object 2, then object 2 for object 5.

출처

Olympiad > USA Computing Olympiad > 2004-2005 Season > USACO February 2005 Contest > Silver 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /