logo AlgoBeat OnlineJudge
登录 注册

#101674. [BZOJ 1674] [Usaco2005]Part Acquisition

内存限制:64 MiB 时间限制:5000 ms 标准输入输出
题目类型:传统 评测方式:文本比较
上传者: 匿名

题目描述

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

输入格式

  • 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.