【题目分析】

最大权闭合子图。

S到集合1容量为获利的大小,集合2到T为所需要付出的相反数。

然后求出最大流,然后用总的获利相减即可。

【代码】

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>

//#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

#define maxn 50005
#define ll long long
#define me 200005
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)

void Finout()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    #endif
}

int Getint()
{
    int x=0,f=1; 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;
}
int h[me<<1],to[me<<1],ne[me<<1],fl[me<<1],en=0,S=0,T=me-1;

void add(int a,int b,int c)
{
//	cout<<"add "<<a<<" "<<b<<" "<<c<<endl;
    to[en]=b; ne[en]=h[a]; fl[en]=c; h[a]=en++;
    to[en]=a; ne[en]=h[b]; fl[en]=0; h[b]=en++;
}

int map[me];

bool tell()
{
    queue <int> q;
    memset(map,-1,sizeof map);
    map[S]=0;
    while (!q.empty()) q.pop();
    q.push(S);
    while (!q.empty())
    {
        int x=q.front(); q.pop();
//        cout<<"bfs"<<x<<endl;
        for (int i=h[x];i>=0;i=ne[i])
        {
//        	cout<<"to "<<to[i]<<endl;
            if (map[to[i]]==-1&&fl[i]>0)
            {
                map[to[i]]=map[x]+1;
                q.push(to[i]);
            }
        }
    }
//    cout<<"over"<<endl;
    if (map[T]!=-1) return true;
    return false;
}

int zeng(int k,int r)
{
    if (k==T) return r;
    int ret=0;
    for (int i=h[k];i>=0&&ret<r;i=ne[i])
        if (map[to[i]]==map[k]+1&&fl[i]>0)
        {
            int tmp=zeng(to[i],min(fl[i],r-ret));
            ret+=tmp; fl[i]-=tmp; fl[i^1]+=tmp;
        }
    if (!ret) map[k]=-1;
    return ret;
}

int n,m,x,a,b,c;
ll ans=0;

int main()
{
	memset(h,-1,sizeof h);
    Finout();
    n=Getint(); m=Getint();
    F(i,1,n)
    {
    	x=Getint();
    	add(i+m,T,x);
	}
    F(i,1,m)
    {
    	a=Getint();
    	b=Getint();
    	c=Getint();
    	add(S,i,c);
    	add(i,m+a,inf);
    	add(i,m+b,inf);
    	ans+=c;
	}
//	cout<<"add over"<<endl;
	ll tmp=0,now=0;
	while (tell()) while (tmp=zeng(S,inf)) now+=tmp;
//	cout<<now<<endl;
	cout<<ans-now<<endl;
}

  

BZOJ 1497 [NOI2006]最大获利 ——网络流的更多相关文章

  1. BZOJ 1497: [NOI2006]最大获利( 最大流 )

    下午到周六早上是期末考试...但是我还是坚守在机房....要挂的节奏啊.... 这道题就是网络流 , 建图后就最大流跑啊跑啊跑... --------------------------------- ...

  2. BZOJ 1497: [NOI2006]最大获利 最小割

    1497: [NOI2006]最大获利 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1497 Description 新的技术正冲击着手 ...

  3. BZOJ 1497: [NOI2006]最大获利(最大权闭合子图)

    1497: [NOI2006]最大获利 Time Limit: 5 Sec  Memory Limit: 64 MB Description 新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机 ...

  4. BZOJ 1497: [NOI2006]最大获利

    1497: [NOI2006]最大获利 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 4572  Solved: 2239[Submit][Status] ...

  5. BZOJ 1497: [NOI2006]最大获利(最大权闭合图)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1497 题意: 思路: 论文题,只要看过论文的话就是小菜一碟啦~ 每个用户群i作为一个结点分别向相应的 ...

  6. bzoj 1497 [NOI2006]最大获利【最大权闭合子图+最小割】

    不要被5s时限和50000点数吓倒!大胆网络流!我一个5w级别的dinic只跑了1s+! 看起来没有最大权闭合子图的特征--限制,实际上还是有的. 我们需要把中转站看成负权点,把p看成点权,把客户看成 ...

  7. BZOJ.1497.[NOI2006]最大获利(最小割 最大权闭合子图Dinic)

    题目链接 //裸最大权闭合子图... #include<cstdio> #include<cctype> #include<algorithm> #define g ...

  8. 1497: [NOI2006]最大获利(最大权闭合子图)

    1497: [NOI2006]最大获利 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 5503  Solved: 2673 Description 新的技 ...

  9. BZOJ 1497 JZYZOJ 1344 [NOI2006]最大获利 网络流 最大权闭合图

    http://www.lydsy.com/JudgeOnline/problem.php?id=1497 http://172.20.6.3/Problem_Show.asp?id=1344   思路 ...

随机推荐

  1. HDU 3038 How Many Answers Are Wrong (并查集)---并查集看不出来系列-1

    Problem Description TT and FF are ... friends. Uh... very very good friends -________-bFF is a bad b ...

  2. JSP 基础

    定义 JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术. JSP这门技术的最大的特点在于,写jsp就像在写html,但它相 ...

  3. codeforces 558/C Amr and Chemistry(数论+位运算)

    题目链接:http://codeforces.com/problemset/problem/558/C 题意:把n个数变成相同所需要走的最小的步数易得到结论,两个奇数不同,一直×2不可能有重叠枚举每个 ...

  4. android 5.0新特性学习--RecyclerView

    在过去很多年,我们的PC或者手机设备都是采用拟物化的设计风格,IOS采用扁平化的特性,android在2014年IO大会上说采用Material Design的设计风格,显示效果不能过于生硬的转换,而 ...

  5. 二分图最大匹配 Hopcroft-Karp算法模板

    #include <iostream> #include <cstdlib> #include <cstdio> #include <cstring> ...

  6. 首页商品图片显示错位,easy-popular批量上传

    =============关于zencart批量商品管理的说明================== 首先,安装好批量商品管理模块,设置 /tempEP 目录可写二.确认你已经在后台增加了一些分类目录. ...

  7. context-param与init-param的区别与作用

    <context-param>的作用: web.xml的配置中<context-param>配置作用 1. 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件 ...

  8. 转:Eclipse Debug 界面应用详解——Eclipse Debug不为人知的秘密

    今天浏览csdn,发现一文详细的描述了Eclipse Debug中的各个知识点,非常详尽!特此记录. Eclipse Debug不为人知的秘密 http://blog.csdn.net/mgoann/ ...

  9. 解决getJSON的缓存问题

    $.getJSON("/portal/edu/getAllEdu?adr="+Math.random(),function(data){

  10. AnimationSet的使用

    Animations的使用(3) 1 AnimationSet的使用方法 什么是AnimationSet 1 AnimationSet是Animation的子类 2 一个AnimationSet包含了 ...