题意:
有向环覆盖。最小权值。
思路:
拆点法,每个点i拆成Xi,Yi,原图中的u->v对应二分图中的Xu -> Yv,把权值取反,就转化为最大权完美匹配了。
Ps: 注意重边!
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
const int maxn = 100+5;
int n;
int G[maxn][maxn];
int lx[maxn], ly[maxn];
int cx[maxn], cy[maxn];
int visx[maxn], visy[maxn];
int slack[maxn];
bool GetAugumentPath(int u){
visx[u] = 1;
for(int i = 0; i < n; ++i){
if(visy[i]) continue;
int d = lx[u] + ly[i] - G[u][i];
if(d == 0){
visy[i] = 1;
if(cy[i] == -1||GetAugumentPath(cy[i])){
cx[u] = i;
cy[i] = u;
return true;
}
}
else
slack[i] = min(slack[i]