# LOJ6046 价

Posted by yjjr's blog on January 1, 2018

# 分析

30分——爆搜 40分——加一个特判（全部取）（因为Pi小于0）

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define inf 1000000000
using namespace std;
{
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=606,maxm=5e5+6;
int n,x,y,S,T,last[maxn],que[maxm],h[maxm],cnt=1;
int sum=0,ans=0;
struct edge{int to,next,v;}e[maxm];
void insert(int u,int v,int w){
e[++cnt]=(edge){v,last[u],w};last[u]=cnt;
e[++cnt]=(edge){u,last[v],0};last[v]=cnt;
}

bool bfs(){
que[0]=S;h[S]=0;
reg(now)
if(e[i].v&&h[e[i].to]==-1){
h[e[i].to]=h[now]+1;
que[tail++]=e[i].to;
}
}
return h[T]!=-1;
}

int dfs(int x,int f){
if(x==T)return f;
int w,used=0;
reg(x)
if(h[e[i].to]==h[x]+1){
w=dfs(e[i].to,min(f-used,e[i].v));
e[i].v-=w;e[i^1].v+=w;used+=w;
if(used==f)return f;
}
if(!used)h[x]=-1;
return used;
}

void dinic(){while(bfs())ans+=dfs(S,inf);}
int main()
{
rep(i,1,n){