最小割的建图模式一般是,先算出总收益,然后再通过网络模型进行割边减去部分权值。

然后我们需要思考什么才能带来收益,什么才能有权值冲突。

s连向选的点,t连向不选的点,那么收益的减少量应该就是将s集和t集分开的割边集。

下面说这道题的建图:

点:

  每个人一个点,额外设源汇点。

边:

  源向人连这个人能造成的全部收益(当作雇佣所有人,然后此人造成的收益)

  人与人之间连两人熟悉度*2,呃,题意问题。

  人向汇连雇佣需要花的钱。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <bitset>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF (LL)<<
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int N=;
//Code begin... struct Edge{int p, next; LL w;}edge[N*N*];
int head[N], cnt=, s, t, vis[N];
queue<int>Q;
LL ss[N]; void add_edge(int u, int v, LL w){
edge[cnt].p=v; edge[cnt].w=w; edge[cnt].next=head[u]; head[u]=cnt++;
edge[cnt].p=u; edge[cnt].w=; edge[cnt].next=head[v]; head[v]=cnt++;
}
int bfs(){
int i, v;
mem(vis,-); vis[s]=; Q.push(s);
while (!Q.empty()) {
v=Q.front(); Q.pop();
for (int i=head[v]; i; i=edge[i].next) {
if (edge[i].w>&&vis[edge[i].p]==-) vis[edge[i].p]=vis[v]+, Q.push(edge[i].p);
}
}
return vis[t]!=-;
}
LL dfs(int x, LL low){
int i;
LL a, temp=low;
if (x==t) return low;
for (int i=head[x]; i; i=edge[i].next) {
if (edge[i].w>&&vis[edge[i].p]==vis[x]+) {
a=dfs(edge[i].p,min(edge[i].w,temp));
temp-=a; edge[i].w-=a; edge[i^].w+=a;
if (temp==) break;
}
}
if (temp==low) vis[x]=-;
return low-temp;
}
LL dinic(){
LL sum=;
while (bfs()) sum+=dfs(s,INF);
return sum;
}
int main ()
{
int n;
LL ans=, x;
scanf("%d",&n); s=; t=n+;
FOR(i,,n) scanf("%lld",&x), add_edge(i,t,x);
FOR(i,,n) FOR(j,,n) {
scanf("%lld",&x); ss[i]+=x;
if (i==j||!x) continue;
add_edge(i,j,x*);
}
FOR(i,,n) add_edge(s,i,ss[i]), ans+=ss[i];
LL res=dinic();
printf("%lld\n",ans-res);
return ;
}
05-28 13:10