编程介的小学生
2017-11-15 12:02Water channels
10Problem Description
So many towns are in drought! The mayor is anxious!
Luckily, There is a reservoir on the mountain top, and the mayor wants to use the water there to irrigate the farmland. The only way is to build some NEW channels to connect the towns that in drought to the reservoir directly or indirectly. Now the problem is the mayor wants to konw what is the least number of channels that have to build to connect all the towns in drought to the reservoir directly or indirectly.
Input
The input consists of multiple test cases. Each case begins with a line containing a positive integer n(0 <= n <= 100), following n pairs of towns in the form "A B", means there has been a channel from A to B. The third line contains a positive integer m(0 <= m <= 16), following m lines containing the names of those towns in drought. The last line contains a town's name which the reservoir is in. You should note that the names of the towns only contain 'A' to 'Z',and their length will less than 100.
Output
For each test case, output one line containing the minimum number of channels you have to built.
Sample Input
2
A B
B C
2
B
C
A
1
A B
2
B
C
A
Sample Output
0
1
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 了解golang频道:死锁
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 1个回答
- 等待组和无缓冲通道的竞争状况
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 1个回答
- Water channels这个问题采用C语言给定数字的建立链表怎么做
- r语言
- Golang
- erlang
- 1个回答
- 遇到一个比较模糊的问题,这个问题用二判定怎么实现呢?
- lines
- c语言
- each
- less
- 1个回答
- Desert King
- lines
- as
- Golang
- x
- each
- 2个回答