Uva 208 Firetruck(dfs并查集优化)
2016-07-03 22:37
507 查看
Firetruck |
be able to select routes from the firestations to fires that do not use closed streets.
Central City is divided into non-overlapping fire districts, each containing a single firestation. When a fire is reported, a central dispatcher alerts the firestation of the district where the fire is located and gives a list of possible routes from the firestation
to the fire. You must write a program that the central dispatcher can use to generate routes from the district firestations to the fires.
Input
The city has a separate map for each fire district. Streetcorners of each map are identified by positive integers less than 21, with the firestation always on corner #1. The input file contains several test cases representing different fires in different districts.The first line of a test case consists of a single integer which is the number of the streetcorner closest to the fire.
The next several lines consist of pairs of positive integers separated by blanks which are the adjacent streetcorners of open streets. (For example, if the pair 4 7 is on a line in the file, then the street between streetcorners
4 and 7 is open. There are no other streetcorners between 4 and 7 on that section of the street.)
The final line of each test case consists of a pair of 0's.
Output
For each test case, your output must identify the case by number (CASE #1, CASE #2, etc). It must list each route on a separate line, with the streetcorners written in the order in which they appear on the route. And it mustgive the total number routes from firestation to the fire. Include only routes which do not pass through any streetcorner more than once. (For obvious reasons, the fire department doesn't want its trucks driving around in circles.)
Output from separate cases must appear on separate lines.
The following sample input and corresponding correct output represents two test cases.
一.题目大意和思路
给定一个图,和一个点k,找出图中所有从点1到k的路径,这里我们采用dfs的方法来寻找路径,但这样会超时,所以我们可以采用并查集来优化问题,利用并查集来判断i点和k点是否能连通,如果能的话就dfs这个点,如果不能的话略过。相关文章推荐
- 友盟统计追踪线上版crash位置
- 跟我学Android之七 资源文件
- 黑马程序员——集合
- TextOut显示多行文本的方法
- linux通配符和正则表达式
- Android学习第一篇——Activity的启动模式
- 跟我学Android之七 资源文件
- 跟我学Android之七 资源文件
- QTabWidget标签实现双击关闭(转)
- 扫描二维码界面的搭建,重点是冲击波动画
- objective-c 编程基础(一 基础语法)
- C语言中怎样判断汉字
- Android Studio Gradle Configuration Errors总结
- 华为机试题【3】
- android中Appwidget的使用
- java 常用英语单词
- 使用内存映射文件来提高你程序的性能
- 华为机试题【3】
- 华为机试题【3】
- ORB:新一代 Linux 应用