比赛 |
20120704 |
评测结果 |
WAAAAWAAAAA |
题目名称 |
子集 |
最终得分 |
81 |
用户昵称 |
ZhouHang |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-04 11:21:17 |
显示代码纯文本
/**
*Porb : subseta
*Data : 2012-7-4
*Sol : 最大点权独立集
*/
#include <cstring>
#include <cstdio>
#include <algorithm>
#define MaxN 20100
#define MaxE 6553600
#define oo 200000000
using namespace std;
struct node {
int y,c,other,next;
} e[MaxE];
int n,tot=0,s,t;
int a[MaxN],cur[MaxN],pre[MaxN],dis[MaxN],gap[MaxN],w[MaxN];
void insert(int x,int y,int c,int _other)
{
if (y>2*n+2)
{bool falg =true;}
e[tot].y=y; e[tot].c = c; e[tot].other=_other;
e[tot].next=a[x]; a[x]=tot;
}
int SAP()
{
memset(pre,0,sizeof(pre));
memset(gap,0,sizeof(gap));
memset(dis,0,sizeof(dis));
gap[0] = n; int u = pre[s] = s;
int maxflow = 0, aug = oo;
for (int i=s; i<=t; i++)
cur[i] = a[i];
while (dis[s]<n) {
loop: for (int &i=cur[u]; i; i=e[i].next) {
int v = e[i].y;
if (e[i].c && dis[u]==dis[v]+1) {
aug = min(aug,e[i].c);
pre[v] = u; u = v;
if ( v == t ) {
maxflow += aug;
for (u=pre[u]; v!=s; v=u,u=pre[u]) {
e[cur[u]].c -= aug;
e[e[cur[u]].other].c += aug;
}
aug = oo;
}
goto loop;
}
}
int mindis = n-1;
for (int i=a[u]; i; i=e[i].next) {
int v = e[i].y;
if (e[i].c && mindis>dis[v]) {
cur[u] = i; mindis = dis[v];
}
}
if ((--gap[dis[u]])==0) break;
dis[u] = mindis+1; gap[dis[u]]++;
u = pre[u];
}
return maxflow;
}
int main()
{
freopen("subseta.in","r",stdin);
freopen("subseta.out","w",stdout);
int m,x,y,sum = 0;
scanf("%d",&n);
s = 0; t = 2*n+1;
for (int i=1; i<=n; i++) {
scanf("%d",&w[i]);
sum += w[i];
//s --> i
tot++; insert(s,i,w[i],tot+1);
tot++; insert(i,s,0,tot-1);
//n+i --> t
tot++; insert(n+i,t,w[i],tot+1);
tot++; insert(t,n+i,0,tot-1);
}
scanf("%d",&m);
for (int i=1; i<=m; i++) {
scanf("%d%d",&x,&y);
//x-->n+y
tot++; insert(x,n+y,oo,tot+1);
tot++; insert(n+y,x,0,tot-1);
//y-->n+x
tot++; insert(y,n+x,oo,tot+1);
tot++; insert(n+x,y,0,tot-1);
}
n = 2*n+2;
int ans = sum - SAP()/2;
printf("%d\n",ans);
fclose(stdin); fclose(stdout);
return 0;
}