题目链接 题意:无向图有N(N <= 1000)个节点,M(M <= 10000)条边:从节点1走到节点N再从N走回来,图中不能走同一条边,且图中可能出现重边,问最短距离之和为多少? 思路:很经典的构图(看题解的);每条原图中的边赋予cap为1,表示只走一次.超级源点s和汇点t分别和起点终点连边,cap为2,这里cap为2就直接限制了只能有两次最大流:同时最大流中以权值限制得到的就是最小费用:很注意的一点就是此题为无向图带权值,建图时每条有向边建成两条即总边数为4*M.由于spfa找最短路是有…
题意: 有n个点和m条边,让你从1出发到n再从n回到1,不要求所有点都要经过,但是每条边只能走一次.边是无向边. 问最短的行走距离多少. 一开始看这题还没搞费用流,后来搞了搞再回来看,想了想建图不是很难,因为要保证每条边只能走一次,那么我们把边拆为两个点,一个起点和终点,容量是1,权重是这条路的长度.然后两个端点分别向起点连接容量是1权重是0的边,终点分别向两个端点连容量是1权重是0的边,从源点到1连容量为2权重为0的边,从n到汇点连容量为2权重为0的边. #include<stdio.h>…
Farm Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17230   Accepted: 6647 Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of…
原题 费用流板子题. 费用流与最大流的区别就是把bfs改为spfa,dfs时把按deep搜索改成按最短路搜索即可 #include<cstdio> #include<queue> #include<cstring> #define N 20020 using namespace std; int n,m,src, des, head[N],dis[N],cur[N],ans,cnt=2,s,t, ANS; queue <int> q; bool vis[N]…
题目链接:http://poj.org/problem?id=2135 Farm Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17672   Accepted: 6851 Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000…
描述 When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of which contains his house and the Nth of which contains the big barn. A total M (1 <= M <= 10000)…
Farm Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18150   Accepted: 7023 Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of…
[题目链接] http://poj.org/problem?id=2135 [题目大意] 有一张无向图,求从1到n然后又回来的最短路 同一条路只能走一次 [题解] 题目等价于求从1到n的两条路,使得两条路的总长最短 那么就等价于求总流量为2的费用流 [代码] #include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <queue> #i…
inf开太小错了好久--下次还是要用0x7fffffff #include<stdio.h> #include<string.h> #include<vector> #include<queue> #include<algorithm> using namespace std; const int N=5024; const int inf=0x7fffffff; struct Edge { int from,to,cap,flow,cost;…
POJ 2135 Farm Tour (网络流,最小费用最大流) Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 <= N <= 1000) fields numbered 1..N, the first of which contains his house and the Nth of which contains the b…