A1245 | [COCI-2011_2012-olympiad]#1 KAMPANJA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
The elections are nearing, so President Amabo Kcarab is planning a tour of the States, with speeches in WDC and LA. To provide adequate security, the Secret Service needs to constantly monitor all cities that the President will pass through (including WDC and LA).
Of course, the federal budget needs to be spent responsibly, so the President will not be using AF1, but will be travelling by car. Also, the Secret Service will plan the President's tour from WDC to LA and back to WDC such that the least possible number of cities needs to be monitored.
For this problem, assume that the States consist of N cities, denoted by numbers from 1 to N, and M unidirectional Interstates, with each Interstate linking two different cities. WDC is city number 1, LA number
2.
Write a program to compute the minimum number of cities that need to be monitored such that there exists a path from WDC to LA and back to WDC passing only through monitored cities.
Of course, the federal budget needs to be spent responsibly, so the President will not be using AF1, but will be travelling by car. Also, the Secret Service will plan the President's tour from WDC to LA and back to WDC such that the least possible number of cities needs to be monitored.
For this problem, assume that the States consist of N cities, denoted by numbers from 1 to N, and M unidirectional Interstates, with each Interstate linking two different cities. WDC is city number 1, LA number
2.
Write a program to compute the minimum number of cities that need to be monitored such that there exists a path from WDC to LA and back to WDC passing only through monitored cities.
输入格式
The first line of input contains the two integers N and M (2 ≤ N ≤ 100, 2 ≤ M ≤ 200), the number of cities and the number of Interstates linking the cities, respectively.
Each of the following M lines contains two different integers A, B (1 ≤ A, B ≤ N), the beginning and ending city served by the given Interstate. No two Interstates link the same two cities in the same direction, but two Interstates can link the same two cities in opposite directions.
Each of the following M lines contains two different integers A, B (1 ≤ A, B ≤ N), the beginning and ending city served by the given Interstate. No two Interstates link the same two cities in the same direction, but two Interstates can link the same two cities in opposite directions.
输出格式
The first and only line of output must contain the minimum number of cities that need to be monitored.
输入输出样例
输入 #1
6 7 1 3 3 4 4 5 5 1 4 2 2 6 6 3
输出 #1
6
输入 #2
9 11 1 3 3 4 4 2 2 5 5 3 3 6 6 1 2 7 7 8 8 9 9 1
输出 #2
6
In test data worth a total of 20 points, N will be at most 20.
Note: Test data will ensure that a solution will always exist.
First sample description: The President can take the following route: 1 -> 3 -> 4 -> 2 -> 6 -> 3 -> 4
-> 5 -> 1. Since he needs to pass through each city at least once, the solution is 6.
Note: Test data will ensure that a solution will always exist.
First sample description: The President can take the following route: 1 -> 3 -> 4 -> 2 -> 6 -> 3 -> 4
-> 5 -> 1. Since he needs to pass through each city at least once, the solution is 6.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted