不重叠最短路计数. 先弗洛伊德求一遍两两距离(其实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…
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…
题目链接: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…
人老了就比较懒,故意挑了到看起来很和蔼的题目做,然后套个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…
[题意]给定一个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[…
题目大意:给定一个带权有向图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 路都 是最…
本题就是给出一组cities.然后以下会询问,两个cities之间的最短路径. 属于反复询问的问题,临时我仅仅想到使用Dijsktra+heap实现了. 由于本题反复查询次数也不多,故此假设保存全部最短路径,那么是得不偿失了. 所以还是反复使用Dijsktra吧. 有没有更加好的办法处理反复查询问题呢?还没想到. 本算法纯粹手工打造了,不使用stl.代码非常长非常长,光打一遍就会手软的,呵呵. 原题: You are given a list of cities. Each direct con…
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 题意:给你一个一个n*n(n<=100)的有向图,问你从s到t有多少条路径最短且这些路径没有边重合. 分析: 反过来想,如果我们知道哪些边是最短路径上的边,那么表明这条边必须只能走一边,于是可以把这样的边容量设为1,然后跑s到t的最大流. 于是问题的关键就是如何找出在最短路径上的边. 可以先用floyd算出每两点之间的最短路d[i][j] 如果一条边(u,v)满足…
An undirected, connected graph of N nodes (labeled 0, 1, 2, ..., N-1) is given as graph. graph.length = N, and j != i is in the list graph[i] exactly once, if and only if nodes i and j are connected. Return the length of the shortest path that visits…