传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2893
吐槽:为什么题目是征服王题面是wa2……而且我是冬马党……
而且上次提交是2013年5月……
这题……一眼缩点,缩成DAG,然后问题就是限制起点终点的可重复经过的最小路径覆盖
神奇的费用流:
对于一个点u,拆成u->u' ,连两条边,一条cap=1 cost=1,另一条cap=inf cost=0
s->u cap=inf cost=0,u' -> t cap=inf cost=0
对于原图的边<u,v>: u'->v cap=inf cost=0
跑最大费用流
有cost的边代表这个点经过一次
那么最大费用流每次会尽量走费用多的边,即走尽量多的点,正确性由网络流保证
增广次数即为答案
复杂度?
每次增广至少有1个cost,总共有n个cost,最坏增广n次
Code:
#include<bits/stdc++.h>
#undef INT_MAX
#define INT_MAX 100000
using namespace std;
const int maxn=1010;
int getint(){
int res=0;char c=getchar();
while(!isdigit(c))c=getchar();
while(isdigit(c))res=res*10+