PAT顶级题解目录​​​​​​​

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 N (≤500). Then N 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] > 0 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 3 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:

EAR MAR 11
EAR AAA 300
EAR BBB 400
AAA BBB 100
AAA CCC 400
AAA MAR 300
BBB DDD 400
AAA DDD 400
DDD AAA 100
CCC MAR 400
DDD CCC 200
DDD MAR 300

Sample Output:

700

题目大意:给出起点和终点,和相关的路径,其中每条路径有容量限制,现在要求能从起点运送到终点的最大容量,要保证不超过每条路径的容量。

解题思路:最大流问题。节点的index用unordered_map进行映射。

关于最大流的几种算法可以参考:

https://blog.csdn.net/smartxxyx/article/details/9293665

https://blog.csdn.net/CY05627/article/details/90552189

https://blog.csdn.net/jinli_/article/details/88563542

Edmonds_Karp算法

#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int inf = 0x3f3f3f3f;
struct Edge{int from, to, cap, flow;Edge(int a, int b, int c, int d): from(a), to(b), cap(c), flow(d){}
};
unordered_map<string, int>Index;
vector<Edge> edges;
vector<int> graph[N];
int a[N], p[N]; // a记录起点到每个节点的残量,p最短路树上到节点i的边的序号//在图中添加边,注意由a到b的边序号为i,则b到a的边的序号为i+1。在p[i]^1中药用到这一点
void addedge(string from ,string to,int cap){   if(Index.find(from)==Index.end())Index.insert({from,Index.size()});if(Index.find(to)==Index.end())Index.insert({to,Index.size()});int f=Index[from],t=Index[to];graph[f].push_back(edges.size());edges.push_back(Edge(f,t,cap,0));graph[t].push_back(edges.size());edges.push_back(Edge(t,f,0,0));
}int Edmonds_Karp(int s, int t){int flow = 0;while(true){memset(a, 0, sizeof(a));queue<int> q;q.push(s);a[s] = inf;//BFS更新残量 while(!q.empty()){int temp = q.front();q.pop();for(int x : graph[temp]){Edge &e = edges[x];if(a[e.to] == 0 && e.cap > e.flow){p[e.to] = x;a[e.to] = min(a[temp], e.cap - e.flow);q.push(e.to);}}if(a[t] != 0)break;}if(a[t] == 0)break;for(int u = t; u != s; u = edges[p[u]].from){edges[p[u]].flow += a[t];edges[p[u]^1].flow -= a[t];}flow += a[t];}return flow;
}
int main(){string from, to;int n, cap; cin >> from >> to >> n;Index[from] = 0;Index[to] = 1;while(n--){cin >> from >> to >> cap;addedge(from,to,cap);}printf("%d",Edmonds_Karp(0,1));return 0;
}

1003 Universal Travel Sites (35 分)(C++)相关推荐

  1. PAT顶级 1003 Universal Travel Sites (35分)(最大流)

    题目链接: 1003 Universal Travel Sites (35分) 思路: 题目问stationstationstation的最小容量,变相就是问最多能一次性出发多少人,使得过程中不会超过 ...

  2. PAT-Top-1003 Universal Travel Sites (35分)网络流最大流

    1003 Universal Travel Sites (35分) 题目传送门:1003 Universal Travel Sites (35分) 一.题目大意 二.解题思路 网络流问题,第一次尝试, ...

  3. 1003. Universal Travel Sites (35)

    本题是PAT上顶级一道题目,考察的知识点其实只有一个,最大流问题.用基于广度优先搜索的Edmonds-Karp算法求解.题目意思就是说求解最多能从地球站发送出去的最大人数,在到达目的星球(MAR)上途 ...

  4. 1003. Universal Travel Sites (35)解题报告

    思路 这道题实际上是在问图算法中的最大流问题,使用Edmonds-Karp算法就可以解决. 它的时间复杂度是O(VE^2).具体的算法和证明请参考<算法导论>第六部分图算法第26章最大流. ...

  5. pat顶级1003 Universal Travel Sites (35 point(s))

    欢迎访问我的pat顶级题解目录哦 https://blog.csdn.net/richenyunqi/article/details/86751676 题目描述 算法设计 这道题是图论的最大流问题,关 ...

  6. NBT-19年2月刊4篇35分文章聚焦宏基因组研究

    新年4篇35分文章聚焦宏基因组研究 Nature Biotechnology (NBT,自然生物技术,IF 35.7)在2019年2月刊(https://www.nature.com/nbt/volu ...

  7. NBT-新年4篇35分文章聚焦宏基因组研究

    文章目录 新年4篇35分文章聚焦宏基因组研究 1. 超高速细菌基因组检索技术 摘要 序列搜索方法 2. 宏基因组中设计全面可扩展探针捕获序列多样性 摘要 CATCH设计探针 3. 1520个人类肠道可 ...

  8. PAT甲级1030 Travel Plan (30分):[C++题解]dijkstra求单源最短路、保存路径

    文章目录 题目分析 题目链接 题目分析 来源:PAT网站 分析 dijkstra模板默写过来,然后多了一个保存路径,使用数组pre[N]记录最短路上每个点的前驱,通过pre数组保存到vector中 v ...

  9. PTA 1002 Business (35分)

    想试试PTA Top Level的难度,然后随便来了一题~ 1002 Business (35分) As the manager of your company, you have to carefu ...

最新文章

  1. i-jetty环境搭配与编译
  2. iphone导出照片到电脑_如何更改 iPhone 照片格式?
  3. 准时制 jit 减少库存
  4. 一步一步的写出你自己的makefile文件
  5. java制作安卓客户端_制作网页的Android客户端(一)
  6. 新网 云服务器,云服务器的使用教程
  7. Java界面排号系统_【前端系统】javaweb技术的医院门诊在线预约及排号管理系统的实现...
  8. Windows python tensorflow 安装
  9. 大数据初学者的福利——Hadoop快速入门教程
  10. php千图网解析,PHP素材资源解析平台源码V8.0(thinkPHP框架内核)
  11. Java 实现 pdf 和 Excel 的生成及数据动态插入、导出
  12. spring 项目中设置maven镜像源
  13. Chrome浏览器占用CPU资源过高(Software Reporter Tool)
  14. js爬山之作用域和自由变量~~狂徒李四
  15. 文件名依照字符串和数字进行排序
  16. 区块链的未来发展前景
  17. hdu4069 Squiggly Sudoku
  18. 文本域(Textarea)背景的美化
  19. 数字化转型是新瓶装旧酒吗?
  20. Facebook公布2012年Q2财务数据

热门文章

  1. Apple Developer:苹果客服中心电话
  2. CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.co
  3. 山东工商学院 计算机 银行,山东工商学院与中国工商银行成为战略合作伙伴
  4. 软件工程导论---概述--软件危机
  5. 蓝桥杯scratch集训操作题:绘制蜘蛛网
  6. python dataframe的某一列变为list_NumPy中的ndarray与Pandas的Series和DataFrame之间的区别与转换...
  7. 遗传算法求函数最小值(多维)2
  8. python关键词 打标签详解_Python学习日记13|利用python制作简书首页热门文章关键词标签云...
  9. Python资源大全中文版
  10. GNS3路由器host not reachable问题解决方案