http://acm.hdu.edu.cn/showproblem.php?pid=3002

 

最小割模板

#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
const int N = 1e6+;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T;
void testcase(){
printf("Case #%d: ",++T);
}
const int MAXN = ;
const int MAXM = ;
int maz[MAXN][MAXN];
int v[MAXN],dist[MAXN];
bool visit[MAXN];
int n,m;
int StoerWagner(int n){
int cut = inf;
for(int i=;i<n;i++) v[i]=i;
while(n>){
int k=,pre=;
for(int i=;i<n;++i){
dist[v[i]]=maz[v[]][v[i]];
if(dist[v[i]]>dist[v[k]]) k=i;
}
mset(visit,false);
visit[v[]]=true;
for(int i=;i<n;i++){
if(i==n-){
cut=min(cut,dist[v[k]]);
for(int j=;j<n;j++){
maz[v[pre]][v[j]] += maz[v[j]][v[k]];
maz[v[j]][v[pre]] += maz[v[j]][v[k]];
}
v[k]=v[--n];
}
visit[v[k]]=true;
pre = k,k=-;
for(int j=;j<n;j++){
if(!visit[v[j]]){
dist[v[j]] += maz[v[pre]][v[j]];
if(k==- || dist[v[k]]<dist[v[j]]) k=j;
}
}
}
}
return cut;
} int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int n,m;
while(~scdd(n,m)){
mset(maz,);
int x,y,w;
for(int i=;i<m;i++){
scddd(x,y,w);
maz[x][y]+=w;
maz[y][x]+=w;
}
cout<<StoerWagner(n)<<endl;
}
return ;
}

HDU - 3002 King of Destruction(最小割)的更多相关文章

  1. HDU 4289:Control(最小割)

    http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可 ...

  2. HDU 3452 Bonsai(网络流之最小割)

    题目地址:HDU 3452 最小割水题. 源点为根节点.再另设一汇点,汇点与叶子连边. 对叶子结点的推断是看度数是否为1. 代码例如以下: #include <iostream> #inc ...

  3. HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  4. HDU 3526 Computer Assembling(最小割)

    http://acm.hdu.edu.cn/showproblem.php?pid=3526 题意:有个屌丝要配置电脑,现在有n个配件需要购买,有两家公司出售这n个配件,还有m个条件是如果配件x和配件 ...

  5. HDU 3251 Being a Hero(最小割+输出割边)

    Problem DescriptionYou are the hero who saved your country. As promised, the king will give you some ...

  6. HDU 6126.Give out candies 最小割

    Give out candies Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Other ...

  7. HDU 6214 Smallest Minimum Cut 最小割,权值编码

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...

  8. HDU 3691 Nubulsa Expo(全局最小割)

    Problem DescriptionYou may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa i ...

  9. HDU 6214 Smallest Minimum Cut (最小割且边数最少)

    题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...

随机推荐

  1. jquery的extend方法(源码解析)

    1.前段时间一直忙于研究数据可视化(d3.js,three.js) 以及 php的 laravel框架,生活上也遇到很多事情,这大概就是人生中的迷茫期吧. 回想起,刚出来工作的时候,目标很明确,要学习 ...

  2. PDB自动启动以及Oracle Pfile的参数修改示范

    1. Oracle12c 可以使用PDB的模式进行创建, 但是他一般不会自动启动,所以可以穿件一个触发器进行处理 创建语句 CREATE TRIGGER open_all_pdbs AFTER STA ...

  3. [日常工作]非Windows Server 系统远程经常断以及提高性能的方法

    1. 公司内有不少windows xp windows 7 这样的操作系统的机器在机房里面用来跑自动化脚本或者是其他用处. 经常有人反馈机器过一段时间连不上, 其实这一点是一个非常小的地方 很多机器上 ...

  4. linux系统安全审计简单设置

    应用安全-安全审计日志目录  /var/log/audit/audit.log [root@localhost audit]# cd /etc/audit/[root@localhost audit] ...

  5. js對象

    js聲明一個數據,即使沒有賦值,也是創建了一個對象: js的所有數據都是對象,對象裡面有屬性也有方法,屬性方法是對象中的成員: 訪問對象的屬性:objectname.屬性名 訪問對象的方法:objec ...

  6. [luogu5008]逛庭院

    首先我们看到数据范围.妈耶!数据这么大,一开始还想用个DP来做,但是看着就不行,那么根据这个数据范围,我们大致可以猜到这道题的算法是一个贪心,那么我们怎么贪呢? 我们首先还是先画一个图: 样例解释一下 ...

  7. 使用sharepoint里Open with explorer功能

    使用这个功能时,遇到几个问题: 1. 当点击library时,ie报错:A problem with this webpage caused Internet Explorer to close an ...

  8. PendingIntent的使用

    1, 构造intent Intent mIntent = new Intent("android.intent.action.MAIN"); ComponentName comp ...

  9. 洛谷P3768 简单的数学题

    解: 神奇的一批......参观yyb巨神的博客. 大致思路就是第一步枚举gcd,发现后面有个限制是gcd=1,用反演,得到的F(x)是两个等差数列求积. 然后发现有个地方我们除法的除数是乘积,于是换 ...

  10. A1020. Tree Traversals

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...