题意
自己看。。
题解
一看就很有网络流的样子。。
代价最小,不就是最小割嘛
我们将节点黑白染色,正权为白,反之为黑
建图方法如下:
S—–白点
黑点——>T
然后能影响到的点连一下就好了。。
至于权值就是他们的S(或相反数)
CODE:
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=505;
const int MAX=1<<30;
int X[N],Y[N],R[N],S[N];
int n;
struct qq{int x,y,z,last;}s[N*N*2];
int num,last[N];
int st,ed;
void init (int x,int y,int z)
{
num++;
s[num].x=x;s[num].y=y;s[num].z=z;
s[num].last=last[x];
last[x]=num;
swap(x,y);z=0;
num++;
s[num].x=x;s[num].y=y;s[num].z=z;
s[num].last=last[x];
last[x]=num;
}
int ans=0;
int dis (int x,int y){return (X[x]-X[y])*(X[x]-X[y])+(Y[x]-Y[y])*(Y[x]-Y[y]);}
int h[N];
bool Bt ()
{
memset(h,-1,sizeof(h));h[st]=1;
queue<int> q;
q.push(st);
while (!q.empty())
{
int x=q.front();q.pop();
for (int u=last[x];u!=-1;u=s[u].last)
{
int y=s[u].y;
if (s[u].z>0&&h[y]==-1)
{
h[y]=h[x]+1;
q.push(y);
}
}
}
return h[ed]!=-1;
}
int mymin (int x,int y){return x<y?x:y;}
int dfs (int x,int f)
{
if (x==ed) return f;
int s1=0;
for (int u=last[x];u!=-1;u=s[u].last)
{
int y=s[u].y;
if (s[u].z>0&&h[y]==h[x]+1&&s1<f)
{
int lalal=dfs(y,mymin(s[u].z,f-s1));
s1+=lalal;
s[u].z-=lalal;
s[u^1].z+=lalal;
}
}
if (s1==0) h[x]=-1;
return s1;
}
int main()
{
num=1;memset(last,-1,sizeof(last));
scanf("%d",&n);st=n+1;ed=st+1;
for (int u=1;u<=n;u++)
{
scanf("%d%d%d%d",&X[u],&Y[u],&R[u],&S[u]);
if (S[u]>0) {ans=ans+S[u];init(st,u,S[u]);}
else init(u,ed,-S[u]);
}
for (int u=1;u<=n;u++)
for (int i=1;i<=n;i++)
{
if (u==i) continue;
if (dis(u,i)<=R[u]*R[u]) init(u,i,MAX);
}
/*for (int u=2;u<=num;u+=2)
printf("%d %d %d\n",s[u].x,s[u].y,s[u].z);*/
while (Bt()==true) ans=ans-dfs(st,MAX);
printf("%d\n",ans);
return 0;
}