【最小路径覆盖】Assassin`s Creed (II)
2014-12-11 12:22
281 查看
Description
![](http://lightoj.com/data/problems/desc/1429/a.jpg)
Ezio needs to kill N targets located in N different cities.
The cities are connected by some one way roads. As time is short, Ezio can send a massage along with the map to the assassin's bureau to send some assassins who will start visiting cities and killing the targets. An assassin can start from any city, he may
visit any city multiple times even the cities that are already visited by other assassins. Now Ezio wants to find the minimum number of assassins needed to kill all the targets.
Input
Input starts with an integer T (≤ 70), denoting the number of test cases.
Each case starts with a blank line. Next line contains two integers N (1 ≤ N ≤ 1000) and M (0 ≤ M ≤ 10000), where N denotes the number of cities and M denotes
the number of one way roads. Each of the next M lines contains two integers u v (1 ≤ u, v ≤ N, u ≠ v) meaning that there is a road from u to v. Assume that there can be at most one road from
a city u to v.
Output
For each case, print the case number and the minimum number of assassins needed to kill all targets.
Sample Input
3
5 4
1 2
1 3
4 1
5 1
7 0
8 8
1 2
2 3
3 4
4 1
1 6
6 7
7 8
8 6
Sample Output
Case 1: 2
Case 2: 7
Case 3: 2
先SCC缩点,再路径覆盖
注意这里不能用floyd传递闭包
对每个点bfs一次才O(nm),留它何用!!!!!
![](http://lightoj.com/data/problems/desc/1429/a.jpg)
Ezio needs to kill N targets located in N different cities.
The cities are connected by some one way roads. As time is short, Ezio can send a massage along with the map to the assassin's bureau to send some assassins who will start visiting cities and killing the targets. An assassin can start from any city, he may
visit any city multiple times even the cities that are already visited by other assassins. Now Ezio wants to find the minimum number of assassins needed to kill all the targets.
Input
Input starts with an integer T (≤ 70), denoting the number of test cases.
Each case starts with a blank line. Next line contains two integers N (1 ≤ N ≤ 1000) and M (0 ≤ M ≤ 10000), where N denotes the number of cities and M denotes
the number of one way roads. Each of the next M lines contains two integers u v (1 ≤ u, v ≤ N, u ≠ v) meaning that there is a road from u to v. Assume that there can be at most one road from
a city u to v.
Output
For each case, print the case number and the minimum number of assassins needed to kill all targets.
Sample Input
3
5 4
1 2
1 3
4 1
5 1
7 0
8 8
1 2
2 3
3 4
4 1
1 6
6 7
7 8
8 6
Sample Output
Case 1: 2
Case 2: 7
Case 3: 2
先SCC缩点,再路径覆盖
注意这里不能用floyd传递闭包
对每个点bfs一次才O(nm),留它何用!!!!!
相关文章推荐
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
- 【LightOJ】Assassin`s Creed (II) (缩点,传递闭包,二分图匹配,最小路径覆盖)
- LightOJ - 1429-Assassin`s Creed (II)(tarjan找环缩点+bfs+最小路径覆盖)
- lightoj 1429 - Assassin`s Creed (II) 【BFS预处理传递闭包 + SCC缩点 + DAG最小路径覆盖】
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- HDU 3991 Harry Potter and the Present II 最小路径覆盖 建图
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- HDU 3991 Harry Potter and the Present II(Floyd+DAG最小路径覆盖)
- 二分图之最小路径覆盖
- 二分图的应用:最小覆盖,最小边覆盖,最大独立子集,最小路径覆盖
- Air Raid 最小路径覆盖问题
- 最小点覆盖,最小边覆盖,最大匹配,最小路径覆盖,最大独立集总结。
- POJ2594-Treasure Exploration(最小路径覆盖变形)
- 洛谷P2764 最小路径覆盖问题(最大流)
- 洛谷 P2764(最小路径覆盖=节点数-最大匹配)
- 拦截导弹_codevs1044_最小路径覆盖+DP+水