若一个球队总场次是n,胜场是x,负场就是n-x,可以列出一个收益的柿子,只有x一个变量,拆边跑费用流
code:
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;
inline void down(int &x,const int &y){if(x>y)x=y;}
const int maxn = 11000;
const int maxm = 110000;
int n,m,st,ed;
struct edge
{
int y,c,d,nex;
edge(){}
edge(const int _y,const int _c,const int _d,const int _nex){y=_y;c=_c;d=_d;nex=_nex;}
}a[maxm<<1]; int len,fir[maxn];
inline void ins(const int x,const int y,const int c,const int d)
{
a[++len]=edge(y,c,d,fir[x]); fir[x]=len;
a[++len]=edge(x,0,-d,fir[y]); fir[y]=len;
}
struct node
{
int x,i;
node(){}
node(const int &_x,const int &_i){x=_x;i=_i;}
};
inline bool operator <(node x,node y){return x.x>y.x;}
priority_queue<node>q;
int pos[maxn],pre[maxn],d[maxn];
bool bfs()
{
for(int i=1;i<=ed;i++) d[i]=inf; d[st]=0;
q.push(node(0,st));
while(!q.empty())
{
const node x=q.top(); q.pop();
if(x.x!=d[x.i]) continue;
for(int k=fir[x.i];k;k=a[k].nex)
{
const int y=a[k].y;
if(d[y]>x.x+a[k].d&&a[k].c)
{
d[y]=x.x+a[k].d;
pos[y]=x.i; pre[y]=k;
q.push(node(d[y],y));
}
}
}
return d[ed]!=inf;
}
int Flow()
{
int re=0;
while(bfs())
{
int k=inf;
for(int i=ed;i!=st;i=pos[i]) down(k,a[pre[i]].c);
re+=k*d[ed];
for(int i=ed;i!=st;i=pos[i])
{
a[pre[i]].c-=k;
a[pre[i]^1].c+=k;
}
}
return re;
}
int e[maxn][2];
int N[maxn],wn[maxn];
int A[maxn],B[maxn];
int main()
{
len=1; //
scanf("%d%d",&n,&m); st=n+m+1,ed=st+1;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d%d",&wn[i],&N[i],&A[i],&B[i]);
N[i]+=wn[i];
}
for(int i=1;i<=m;i++)
scanf("%d%d",&e[i][0],&e[i][1]),N[e[i][0]]++,N[e[i][1]]++;
int ans=0;
for(int i=1;i<=n;i++)
{
ans+=B[i]*N[i]*N[i]+(A[i]+B[i])*wn[i]*wn[i]-2*B[i]*N[i]*wn[i];
for(int j=wn[i]+1;j<=N[i];j++)
{
ins(m+i,ed,1,(A[i]+B[i])*(2*j-1)-2*B[i]*N[i]);
}
}
for(int i=1;i<=m;i++)
{
ins(st,i,1,0);
ins(i,m+e[i][0],1,0);
ins(i,m+e[i][1],1,0);
}
printf("%d\n",ans+Flow());
return 0;
}