bzoj#P1950. [Ceoi2006] Link
[Ceoi2006] Link
题目描述
Webmaster Kirk is reorganizing his school's website. There are a number of pages on the website and the content is fine, but he noticed that the pages are not properly linked. In fact, every page contains exactly one link, pointing to some other page in the website. This is a poor design – starting from the homepage, a visitor will usually have to follow many links before reaching the page of his interest, and some pages might not be reachable from the homepage at all. As a first step, he wants to add a few links so that every page can be quickly accessed from the homepage. New links can be added anywhere in the website.
The website contains pages marked with integers to and the homepage is marked with the number .
There are also links; each page contains exactly one link pointing to some different page. For an integer , a website is said to be -reachable if every page on the website other than the homepage can be reached from the homepage by following at most links.
Write a program that, given the description of the website and an integer , finds the minimum number of links that need to be added in order to make the website -reachable.
给定 个点 条边的有向图,要求添最小的边,使得点 到达其他所有点的最短路长度不超过 。
输入格式
The first line of input contains two integers and – the number of pages and the target maximum number of links to be followed. Each of the following lines contains two different integers and (, ) meaning that the link on page points to page .
输出格式
The first and only line of output should contain a single integer, the minimum number of additional links required to make the website -reachable.
14 4
1 2
2 3
3 4
4 5
7 5
5 6
6 3
8 10
10 9
9 8
14 13
13 12
12 11
11 14
3
样例说明 1
One possible solution is to add the links , and .
数据规模与约定
对于 的数据,,。