[Usaco2005]Part Acquisition

时间限制:5s      空间限制:64MB

题目描述

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="" types="" objects="" (numbered="" 1..k)="" planet="" in="" cluster="" desires,="" and="" products="" they="" to="" trade.="" no="" has="" developed="" currency,="" so="" work="" under="" barter="" system:="" all="" trades="" consist="" party="" exactly="" one="" object="" (presumably="" different="" types).="" start="" from="" earth="" canister="" high="" quality="" hay="" (item="" 1),="" desire="" new="" milking="" machine="" k).="" help="" them="" find="" best="" way="" make="" series="" at="" planets="" get="" item="" k.="" if="" this="" task="" is="" impossible,="" output="" -1.="" p="">


输入格式

* 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).


样例输入

6 5   //6个星球,希望得到5,开始时你手中有1号货物.
1 3   //1号星球,希望得到1号货物,将给你3号货物
3 2
2 3
3 1
2 5
5 4

样例输出

4


OUTPUT DETAILS:

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.

提示

没有写明提示


题目来源

Silver

Menuappsclose