买了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)
{