7407: Choose your own path(Problem J5)

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:4 解决:2

题目描述

输入

输出

The output will be two lines. The first line will contain Y if all pages are reachable, and N otherwise. 
The last line will contain a non-negative integer K, which is the shortest path a reader can take while reading this book. There will always be a finite shortest path.

样例输入 复制

3
2 2 3
0
1 1

样例输出 复制

Y
2

提示

Every page is reachable, since from page 1, we can reach pages 2 and 3. The shortest path is the path 1 → 2, which contains two pages.

来源/分类