# 【GDSOI2018模拟4.19】排列

## code

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>;

using namespace std;

const int INF=1e9;

struct arr{
int x,y,w,next;
}edge[1000000];
int ls[100000];
int cur[100000];
int f[1000000];
int sign[100000];
int edge_m=1;
int ans;
int s,t;
int n,m;

{
edge_m++;
edge[edge_m]=(arr){x,y,w,ls[x]},f[edge_m]=w,ls[x]=edge_m,cur[x]=edge_m;
edge_m++;
edge[edge_m]=(arr){y,x,w,ls[y]},f[edge_m]=0,ls[y]=edge_m,cur[y]=edge_m;
}

int dis[100000];

bool bfs()//bfs判断是否继续。
{
memset(dis,-1,sizeof(dis));
queue<int> q;
dis[s]=0;
q.push(s);
do
{
int x=q.front();
q.pop();
for (int i=ls[x];i;i=edge[i].next)
{
if ((f[i])&&(dis[edge[i].y]==-1))
{
dis[edge[i].y]=dis[x]+1;
q.push(edge[i].y);
if (edge[i].y==t) return true;
}
}
}while (!q.empty());
return false;
}

int find(int x,int min_)//找增广路。
{
if (x==t) return min_;
int rec=min_;
for (int i=cur[x];i;i=edge[i].next)
{
if ((f[i]!=0)&&(dis[x]+1==dis[edge[i].y]))
{
int k=find(edge[i].y,min(rec,f[i]));
if (k!=0) sign[x]=edge[i].y;
f[i]-=k;
f[i^1]+=k;
rec-=k;
if (rec==0) return min_;
}
}
if (rec==min_) dis[x]=-1;
return min_-rec;
}

int dinic()
{
while (bfs())
{
for (int i=0;i<=t;i++) cur[i]=ls[i];
ans-=find(s,INF);
}
printf("%d",ans);
}

int a[100000];

int main()
{
//freopen("permutation.in","r",stdin);
//freopen("permutation.out","w",stdout);
scanf("%d%d",&n,&m);
s=n*2+1; t=s+1;
ans=0;
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for (int i=1;i<=n;i++)
{
if (a[i]>0)
{
ans+=a[i];
}
else
}
for (int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
}
dinic();
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120