HDU - 3002 King of Destruction(最小割)
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(最小割)的更多相关文章
- HDU 4289:Control(最小割)
http://acm.hdu.edu.cn/showproblem.php?pid=4289 题意:有n个城市,m条无向边,小偷要从s点开始逃到d点,在每个城市安放监控的花费是sa[i],问最小花费可 ...
- HDU 3452 Bonsai(网络流之最小割)
题目地址:HDU 3452 最小割水题. 源点为根节点.再另设一汇点,汇点与叶子连边. 对叶子结点的推断是看度数是否为1. 代码例如以下: #include <iostream> #inc ...
- 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 ...
- HDU 3526 Computer Assembling(最小割)
http://acm.hdu.edu.cn/showproblem.php?pid=3526 题意:有个屌丝要配置电脑,现在有n个配件需要购买,有两家公司出售这n个配件,还有m个条件是如果配件x和配件 ...
- HDU 3251 Being a Hero(最小割+输出割边)
Problem DescriptionYou are the hero who saved your country. As promised, the king will give you some ...
- HDU 6126.Give out candies 最小割
Give out candies Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- HDU 6214 Smallest Minimum Cut 最小割,权值编码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...
- HDU 3691 Nubulsa Expo(全局最小割)
Problem DescriptionYou may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa i ...
- HDU 6214 Smallest Minimum Cut (最小割且边数最少)
题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...
随机推荐
- js原生函数
arguments:代表所有的形参的集合: 可以通过arguments: cosole.log(arguments):打印所有参数 console.log(arguments[i]);可以通过访问下标 ...
- wps word改多级编号为2.1
右键标题1, 修改样式 编号 多级编号 标题1 2 3 右键标题2 修改样式 选择格式-编号 选择多级编号-标题1 2 3 直接点确定,OK. ---------------------------- ...
- Mysql 乐观锁
转载:http://chenzhou123520.iteye.com/blog/1863407 乐观锁介绍: 乐观锁( Optimistic Locking ) 相对悲观锁而言,乐观锁假设认为数据一般 ...
- matplotlib之直接保存图片
自动保存图表:pyplot.savefig('D:\\pic.png'),替代了 pyplot.show(). # 使用matplotlib.pyplot.scatter绘制散点 import mat ...
- dfs和bfs(链式前向星实现)
dfs代码: #include<iostream>#include<Algorithm>#include<cstring>#include<cstdio> ...
- docker--命令详解
查看版本: docker --version 查看docker信息: docker info 进入容器: docker exec -it bb /bin/bash #在容器中执行一个bash可以操作容 ...
- day9-13 linux基础
有道云笔记链接 http://note.youdao.com/noteshare?id=207be3d6bd79e9ff2e30b160bca1fd87
- Windows Server 脚本记录Apache、Mysql 每分钟并发数
打开windows server 计划任务管理器.定时执行如下的Bat脚本即可. 在D盘新建一个monitor文件夹,创建ApacheMysql.bat文件.内容如下: 在monitor文件夹中新建m ...
- 隐藏SharePoint 2013 team sites里的follow按钮
cls $featureid = 'a7a2793e-67cd-4dc1-9fd0-43f61581207a'$webapps = Get-spWebApplicationforeach($webap ...
- C代码快速构建框架
#include "stdio.h" typedef char int8_t; typedef short int16_t; typedef int int32_t; typede ...