1497

思路:

  最小割;

来,上代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 55005
#define maxm 1005005
#define INF 0x7fffffff int deep[maxn],que[maxm],F[maxm],cnt=;
int n,m,s,t=maxn-,head[maxn],E[maxm],V[maxm]; inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} inline void edge_add(int u,int v,int f)
{
E[++cnt]=head[u],V[cnt]=v,F[cnt]=f,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,F[cnt]=,head[v]=cnt;
} inline bool bfs()
{
memset(deep,-,sizeof(deep));
int h=,tail=;que[]=s,deep[s]=;
while(h<tail)
{
int now=que[h++];
for(int i=head[now];i;i=E[i])
{
if(F[i]>&&deep[V[i]]<)
{
deep[V[i]]=deep[now]+;
if(V[i]==t) return true;
que[tail++]=V[i];
}
}
}
return false;
} int flowing(int now,int flow)
{
if(now==t||flow<=) return flow;
int oldflow=;
for(int i=head[now];i;i=E[i])
{
if(F[i]>&&deep[V[i]]==deep[now]+)
{
int pos=flowing(V[i],min(flow,F[i]));
flow-=pos,oldflow+=pos;
F[i]-=pos,F[i^]+=pos;
if(flow==) return oldflow;
}
}
if(oldflow==) deep[now]=-;
return oldflow;
} int main()
{
in(n),in(m);int pos,u,v,sum=;
for(int i=;i<=n;i++) in(pos),edge_add(s,i,pos);
for(int i=;i<=m;i++)
{
in(u),in(v),in(pos);
sum+=pos;
edge_add(u,i+n,INF);
edge_add(v,i+n,INF);
edge_add(i+n,t,pos);
}
pos=;while(bfs()) pos+=flowing(s,INF);
cout<<sum-pos;
return ;
}

AC日记——[NOI2006]最大获利 bzoj 1497的更多相关文章

  1. 1497: [NOI2006]最大获利 - BZOJ

    Description 新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战.THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一 ...

  2. AC日记——[HEOI2012]旅行问题 bzoj 2746

    2746 思路: 建立ac自动机,然后把fail树抽出来: 然后在fail树上走lca(神奇): 代码: #include <cstdio> #include <vector> ...

  3. AC日记——[HNOI2008]GT考试 bzoj 1009

    1009 思路: KMP上走DP(矩阵加速): DP[i][j]表示当前在第i位,同是匹配到不吉利串的第j位的方案数: 代码: #include <bits/stdc++.h> using ...

  4. AC日记——明明的烦恼 bzoj 1005

    1005 思路: prufer编码+组合数: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 #de ...

  5. AC日记——Mato的文件管理 bzoj 3289

    3289 思路: 莫队求区间逆序对个数,树状数组维护: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 500 ...

  6. AC日记——[Scoi2010]序列操作 bzoj 1858

    1858 思路: 恶心: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 struct Tree ...

  7. AC日记——[ZJOI2007]报表统计 bzoj 1058

    1058 思路: 平衡树的题: 然而我的平衡树写一次炸一次QwQ: 而且各种tle: 所以stl水过: 代码: #include <set> #include <cstdio> ...

  8. AC日记——[JSOI2007]建筑抢修 bzoj 1029

    1029 思路: 贪心,而且,stl水过: 然而神特么输出que.size()就错! 代码: #include <queue> #include <cstdio> #inclu ...

  9. AC日记——[JSOI2008]火星人prefix bzoj 1014

    1014 思路: 平衡树+二分答案+hash: 好了懂了吧. 代码: #include <cstdio> #include <cstring> #include <ios ...

随机推荐

  1. Neon Lights in Hong Kong【香港霓虹灯】

    Neon Lights in Hong Kong Neon is to Hong Kong as red phone booths are to London and fog is to San Fr ...

  2. 【Umezawa's Jitte】真正用起来svn来管理版本

    之前用过一次 但是没有真正的用起来 只是知道了一些基本概念 好了 决定开始真正的用这个svn了 参考大神http://www.cnblogs.com/wrmfw/archive/2011/09/08/ ...

  3. P3376 【模板】网络最大流dinic算法

    P3376 [模板]网络最大流 题目描述 如题,给出一个网络图,以及其源点和汇点,求出其网络最大流. 输入输出格式 输入格式: 第一行包含四个正整数N.M.S.T,分别表示点的个数.有向边的个数.源点 ...

  4. TCP/IP网络编程之网络编程和套接字

    网络编程和套接字 网络编程又称为套接字编程,就是编写一段程序,使得两台连网的计算机彼此之间可以交换数据.那么,这两台计算机用什么传输数据呢?首先,需要物理连接,将一台台独立的计算机通过物理线路连接在一 ...

  5. hdu3374 String Problem 最小最大表示法 最小循环节出现次数

    #include <iostream> #include <cstring> #include <cstdio> using namespace std; int ...

  6. linux学习(三) -- lnmp环境切换php版本,并安装相应redis扩展

    原创文章,转载请注明出处   我想配置的环境是ubuntu+nginx+mysql+php+redis,其中php装两个版本,php7和php56 ubuntu+nginx+mysql+php的环境配 ...

  7. python2.X中文乱码

    在IDE下,加上# -- coding: UTF-8 -- 并且保证IDE也是utf-8编码. 在CMD下,这样执行会有乱码,为啥呢,因为cmd下是gbk编码的,你写的代码必须也是gbk编码的,你可以 ...

  8. Cygwin访问盘符、使用别名、彩色显示、使用adb命令

    Cygwin是一个在Windows平台上运行的类UNIX模拟环境.安装过程我就不重复造轮子了,百度一下即可.其中安装的时候需要装哪些包,要看你用到哪些.比如我就是只用adb shell,所以全部默认安 ...

  9. PHP 获取客户端用户 IP 地址

    一般情况下可以使用以下代码获取到用户 IP 地址 echo 'User IP - '.$_SERVER['REMOTE_ADDR']; // 服务器在局域网的话,那么显示的则是内网IP .// 如果服 ...

  10. java之LinkedList.add

    LinkedList: public boolean add(E e) { linkLast(e); return true; } void linkLast(E e) { //last为当前集合的最 ...