博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zoj 2760 How Many Shortest Path 最大流
阅读量:4335 次
发布时间:2019-06-07

本文共 1903 字,大约阅读时间需要 6 分钟。

题目链接:

Given a weighted directed graph, we define the shortest path as the path who has the smallest length among all the path connecting the source vertex to the target vertex. And if two path is said to be non-overlapping, it means that the two path has no common edge. So, given a weighted directed graph, a source vertex and a target vertex, we are interested in how many non-overlapping shortest path could we find out at most.

题目描述:求一个有向图起点到终点的边不相交的最短路径的条数。

算法分析:floyd+最大流。针对网络流算法而建的模型中,s-t对应于实际中每一种方案,所以此题中的s-t就对应于题目中的一条源点到汇点的最短路径,最大流就是最短路径条数。

接下来就是怎么建模的问题:既然s-t对应于一条最短路径,那么s-t路径上的每一条边都是路径中的最短边。所以首先用floyd求出点到点的最短路径,然后枚举每条边判断是否是最短路径上的边,若是,则加入到新建的图中,权值为1。

1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #define inf 0x7fffffff 9 using namespace std; 10 const int maxn=100+10; 11 12 int n,from,to; 13 int dist[maxn][maxn],an[maxn][maxn]; 14 int d[maxn],graph[maxn][maxn]; 15 16 int bfs() 17 { 18 memset(d,0,sizeof(d)); 19 d[from]=1; 20 queue
Q; 21 Q.push(from); 22 while (!Q.empty()) 23 { 24 int u=Q.front() ;Q.pop() ; 25 for (int v=0 ;v
0) 28 { 29 d[v]=d[u]+1; 30 Q.push(v); 31 if (v==to) return 1; 32 } 33 } 34 } 35 return 0; 36 } 37 38 int dfs(int u,int flow) 39 { 40 if (u==to || flow==0) return flow; 41 int cap=flow; 42 for (int v=0 ;v
0) 45 { 46 int x=dfs(v,min(cap,graph[u][v])); 47 cap -= x; 48 graph[u][v] -= x; 49 graph[v][u] += x; 50 if (cap==0) return flow; 51 } 52 } 53 return flow-cap; 54 } 55 56 int dinic() 57 { 58 int sum=0; 59 while (bfs()) sum += dfs(from,inf); 60 return sum; 61 } 62 63 int main() 64 { 65 while (scanf("%d",&n)!=EOF) 66 { 67 for (int i=0 ;i
dist[i][k]+dist[k][j])) 86 dist[i][j]=dist[i][k]+dist[k][j]; 87 } 88 } 89 } 90 //cout<<"dist[from][to]= "<
<

 

转载于:https://www.cnblogs.com/huangxf/p/4299733.html

你可能感兴趣的文章
vue2.0 + element ui 实现表格穿梭框
查看>>
C++11实战——多线程的日志类
查看>>
unity3d iPhone文件目录介绍
查看>>
用ClassName占位和title占位的分析
查看>>
DROP--删除表
查看>>
jQuery选择器总结
查看>>
线程 、进程、协程 三者区别
查看>>
c++常见操作的模板
查看>>
MQ通道配置
查看>>
程序员思维枷锁
查看>>
089-袁佳鹏-实验报告1
查看>>
forward 和redirect的区别
查看>>
android使用软引用构建缓存
查看>>
FastReport.Net使用:[36]"续表"
查看>>
NSBundle介绍
查看>>
C++ mechanisms for polymorphism
查看>>
form提交后,jquery 显示 文本框选择值和下拉框选中值
查看>>
前端优化
查看>>
如何找出错误ora-07445发生时系统执行的语句
查看>>
debain mariadb10配置root
查看>>