PAT「1003 Universal Travel Sites (35分)」
1. 题目
题目链接:PAT「1003 Universal Travel Sites (35分)」 。
Description
After finishing her tour around the Earth, CYLL is now planning a universal travel sites development project. After a careful investigation, she has a list of capacities of all the satellite transportation stations in hand. To estimate a budget, she must know the minimum capacity that a planet station must have to guarantee that every space vessel can dock and download its passengers on arrival.
Input Specification:
Each input file contains one test case. For each case, the first line contains the names of the source and the destination planets, and a positive integer (). Then lines follow, each in the format: source[i]
destination[i]
capacity[i]
where source[i]
and destination[i]
are the names of the satellites and the two involved planets, and capacity[i]
is the maximum number of passengers that can be transported at one pass from source[i]
to destination[i]
. Each name is a string of uppercase characters chosen from {A-Z}
, e.g., ZJU
.
Note that the satellite transportation stations have no accommodation facilities for the passengers. Therefore none of the passengers can stay. Such a station will not allow arrivals of space vessels that contain more than its own capacity. It is guaranteed that the list contains neither the routes to the source planet nor that from the destination planet.
Output Specification:
For each test case, just print in one line the minimum capacity that a planet station must have to guarantee that every space vessel can dock and download its passengers on arrival.
Sample Input:
1 |
|
Sample Output:
1 |
|
2. 题解
分析
很明显的一道网络流题,可以直接上网络流的板子,但是蒟蒻的我,竟然把网络流的板子给忘了,连带那些算法也想不起来了 😦 真菜。只好暴力推流。从起始节点开始,对每个节点的出边使用 dfs 向其后续节点推流,直到推到终止节点,对于当前节点推不过去的流量要返还给父节点。由于可能有环,所以需要对每个节点进行标记,如果当前节点在当前一次推流过程中被访问过,就标记以下,如果推流结束(即逆向返还剩余流时)就取消标记。最终暴力 AC(这都没有 TLE,PAT 上的测试数据真的太弱了!)。
代码
1 |
|
附录
-
Dinic 算法
1 |
|
-
ISAP 算法
1 |
|
-
HLPP 算法
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!