uva1349最优巴士路线设计——有向环覆盖——最小权完美匹配

本文探讨了UVA1349最优巴士路线设计问题,该问题可转化为有向环覆盖和最小权完美匹配。通过拆点法,将原图中的每个点拆分为两个点,并将权值取反,可以将其转换为寻找最大权完美匹配的问题,需要注意处理可能出现的重边情况。
摘要由CSDN通过智能技术生成
题意:

有向环覆盖。最小权值。

思路:

拆点法,每个点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]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值