CCF CSP 2020-06-05 乔乔和牛牛逛超市

买了x才能买y 等价于要想得到y的最大收益就必须连带着把x的最大收益(即使可能<0)也得收下,这个模型是典型的最大权闭合子图,答案应该是图中正的点权和-最小割的容量。最小割跑最大流模板就可得到。但是第二类点的建图方式还没想到,可能是需要拆点。

80分代码(边建反了) 就这也能拿80分? ccf数据好水啊

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
const int N = 100010, M = 2000010;
const LL INF = 2e9;
int n,m,S,T;
int h[N],tot;
struct Edge{
    int to,nxt;
    LL f;
}e[M];
int q[N],d[N],cur[N],w[N];
void add(int a,int b,LL c)
{
    e[tot].to = b, e[tot].f = c, e[tot].nxt = h[a], h[a] = tot ++;
    e[tot].to = a, e[tot].f = 0, e[tot].nxt = h[b], h[b] = tot ++;
}
bool bfs()
{
    memset(d, -1, sizeof d);
    int hh = 0, tt = -1;
    q[++ tt] = S; d[S] = 0; cur[S] = h[S];
    while(hh <= tt)
    {
        int u = q[hh ++];
        for(int i = h[u]; ~i; i = e[i].nxt)
        {
            int to = e[i].to;
            if(d[to] == -1 && e[i].f)
            {
                d[to] = d[u] + 1;
                cur[to] = h[to];
                q[++ tt] = to;
                if(to == T) return true;
            }
        }
    }
    return false;
}
LL dfs(int u,int limit)
{
  
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值