zoj 2760(网络流+floyed)】的更多相关文章

How Many Shortest Path Time Limit: 10 Seconds      Memory Limit: 32768 KB 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 i…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 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…
[题意]给定一个N(N<=100)个节点的有向图,求不相交的最短路径个数(两条路径没有公共边). [思路]先用Floyd求出最短路,把最短路上的边加到网络流中,这样就保证了从s->t的一个流一定是一条最短路,也就保证了网络流建模的正确性. [找最短路上的边] 满足最优子结构的性质:(i, j)是最短路上的边,当且仅当dist[s][i] + edge[i][j] + dist[j][t] = dist[s][t]. 一开始想的是满足dist[s][j] = dist[s][i] + edge[…
人老了就比较懒,故意挑了到看起来很和蔼的题目做,然后套个spfa和dinic的模板WA了5发,人老了,可能不适合这种刺激的竞技运动了…… 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2760 Description Given a weighted directed graph, we define the shortest path as the path who has the smallest leng…
Description 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 tw…
求最小割的问题. 题意:已知网络中有n个源点,m的中转站(也就是节点),一个汇点(编号为0).给出网络,求一些边(增大这个边就可以增大汇点流量的边). 思路:一开始代码只找了有流=0就加入输出数组的情况,然而忽略了流向一条S->T的流有多个边权=0的情况,此时只增大一条边的值是没用的. 所以除了用一次最大流算法后,还需要用两次dfs分别从超级源点S和汇点T开始搜索,这样就可以把有多个0-0-0和单个边权为0的情况判断出来. #include <cstdio> #include <c…
思路: 这题的结论得要看amber的论文,结论就是将求f(x)/b(x)最小转化为求min(f(x)-b(x)*λ),其中x为S集的解空间,f(x)为解的边权和,b(x)为解的边数, λ=f(x)/b(x).λ*为最优解,当且仅当(x属于S)∑min(f(x)-b(x)*λ)==0:故可以将原边权的权值改为w-λ:对λ进行二分枚举,找出答案. #include<cstdio> #include<iostream> #include<cstring> #include&l…
题目大意:给定一个带权有向图G=(V, E)和源点s.汇点t,问s-t边不相交最短路最多有几条.(1 <= N <= 100) 题解:从源点汇点各跑一次Dij,然后对于每一条边(u,v)如果保证d[s][u]+d[u][v]+d[v][t]==d[s][t]就加边1,然后跑最大流就好. 然而为什么不能是d[s][u]+d[u][t]==d[s][t]呢?我给个反例好了. 比如看这个图:(这是我用Gve写的最丑的图了将就看吧) digraph G{ ->[label="]; -&…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 题意:给定一个带权有向图 G=(V, E)和源点 s.汇点 t,问 s-t 边不相交最短路最多有几 条.(1 <= N <= 100) 思路:分别从源点和汇点作一次 Dijkstra,可是流量网络仅仅增加 满足dis[i] + ma[i][j] + (dis[t]-dis[i])==dis[t]的边(u, v)(这样便保证网络中的随意一条 s-t 路都 是最…
不重叠最短路计数. 先弗洛伊德求一遍两两距离(其实spfa或者迪杰斯特拉会更快但是没必要懒得写),然后设dis为st最短距离,把满足a[s][u]+b[u][v]+a[v][t]==dis的边(u,v)连流量为1的边,表示只能走一次.注意这里a数组是弗洛伊德之后的,b是边的原长,然后跑一边最大流即可. 注意两点 特判掉s不能到达t的情况,直接输出0 弗洛伊德之前把所有数组中形如[i][i]的全部置为0,输入可能有trick #include<iostream> #include<cstd…