HDU 3691
一个源点,一个汇点,明显是网络流的问题,但据说用网络流来求最小割,会超时。。囧,那出题的人是怎么想的。。。
用SW的算法来求最小割。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int MAXN=;
const int inf=;
int vis[MAXN],combine[MAXN],wan[MAXN];
int map[MAXN][MAXN];
int n,m,t;
int mincut,S,T; void seacut(){
int Max; int p;
S=T=-;
memset(vis,,sizeof(vis));
memset(wan,,sizeof(wan));
for(int i=;i<n;i++){
Max=-inf;
for(int j=;j<n;j++){
if(!combine[j]&&!vis[j]&&wan[j]>Max){
Max=wan[j]; p=j;
}
}
if(p==T) return;
S=T;T=p;
vis[T]=;
for(int j=;j<n;j++){
if(!combine[j]&&!vis[j]){
wan[j]+=map[T][j];
}
}
}
} void storewanger(){
mincut=inf;
memset(combine,,sizeof(combine));
for(int i=;i<n-;i++){
seacut();
if(wan[T]<mincut) mincut=wan[T];
if(mincut==) return;
combine[T]=;
for(int j=;j<n;j++){
if(!combine[j]){
map[S][j]+=map[T][j];
map[j][S]+=map[j][T];
}
}
}
} int main(){
int u,v,w;
while(scanf("%d%d%d",&n,&m,&t)!=EOF){
if(!n&&!m&&!t) break;
memset(map,,sizeof(map));
for(int i=;i<m;i++){
scanf("%d%d%d",&u,&v,&w);
u--; v--;
map[u][v]+=w;
map[v][u]+=w;
}
storewanger();
printf("%d\n",mincut);
}
return ;
}
HDU 3691的更多相关文章
- HDU 3691 Nubulsa Expo(全局最小割Stoer-Wagner算法)
Problem Description You may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa ...
- HDU 3691 Nubulsa Expo
无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- King of Destruction HDU - 3002 && HDU - 3691(全局最小割)
求无向图的最小割 有没有源点都一样,不影响 #include <iostream> #include <cstdio> #include <sstream> #in ...
- HDU 3691 Nubulsa Expo(全局最小割)
Problem DescriptionYou may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa i ...
- hdu 3691最小割将一个图分成两部分
转载地址:http://blog.csdn.net/xdu_truth/article/details/8104721 题意:题给出一个无向图和一个源点,让你求从这个点出发到某个点最大流的最小值.由最 ...
- 全局最小割StoerWagner算法详解
前言 StoerWagner算法是一个找出无向图全局最小割的算法,本文需要读者有一定的图论基础. 本文大部分内容与词汇来自参考文献(英文,需***),用兴趣的可以去读一下文献. 概念 无向图的割:有无 ...
- 图的连通性问题的小结 (双连通、2-SAT)
图的连通性问题包括: 1.强连通分量. 2.最小点基和最小权点基. 3.双连通. 4.全局最小割. 5.2-SAT 一.强连通分量 强连通分量很少单独出题,一般都是把求强连通分量作为缩点工具. 有三种 ...
- POJ 3691 & HDU 2457 DNA repair (AC自己主动机,DP)
http://poj.org/problem?id=3691 http://acm.hdu.edu.cn/showproblem.php?pid=2457 DNA repair Time Limit: ...
- HDU 2457/POJ 3691 DNA repair AC自动机+DP
DNA repair Problem Description Biologists finally invent techniques of repairing DNA that contains ...
随机推荐
- Nearest-Neighbor Methods(ESL读书笔记)
Nearest-neighbor methods use those observations in the training set T closest in input space to x f ...
- nodejs安装express
最近在看<Node.js开发指南>,看到使用nodejs进行web开发的时候,准备创建ejs项目遇到问题了, 书上命令为: 1 express -t ejs microblog 可是执行后 ...
- Python 39 数据库的数据类型
一:整型 为什么需要 数据分类? 1.为了描述事物更加准确 2.描述起来更方便 3.节省内存空间 例:1 a 你 utf8 下 5个字节 1 a b c unicode 6个字节 mysq ...
- spark作业运行过程之--DAGScheduler
DAGScheduler--stage划分和创建以及stage的提交 本篇,我会从一次spark作业的运行为切入点,将spark运行过程中涉及到的各个步骤,包括DAG图的划分,任务集的创建,资源分配, ...
- POJ 2230 DFS
题意: Bessie 最近做了农场看守,他每天晚上的工作就是巡视农场并且保证没有坏人破坏农场.从谷仓出发去巡视,并且最终回到谷仓. Bessie 视力不是很好,不能像其他农场的看守一样,对农场的每一条 ...
- B - Is your horseshoe on the other hoof?
Problem description Valera the Horse is going to the party with friends. He has been following the f ...
- js动态追加的元素如何触发事件
一般通过js或者jQuery动态添加的元素标签,通过该元素标签.class.id触发事件,是无效的.如下所示: <body> <input type="text" ...
- Objective-C—— @Property详解
实例变量:属性其实说直白点就是 ivar + setter + getter(实例变量+存取方法),不过在OC中属性多了字面量这一系列特殊关键字使得OC属性有些不同. 成员属性我们应该都使用过,比如现 ...
- W3C标准冒泡、捕获机制
(一) 捕获和冒泡如何相互影响 我们来做几个任务吧! 有一个前提,#parent为标签,#child为子标签,他们是嵌套关系支线任务1 //捕获模式 document.getElementById(' ...
- android指纹识别、拼图游戏、仿MIUI长截屏、bilibili最美创意等源码
Android精选源码 一个动画效果的播放控件,播放,暂停,停止之间的动画 用 RxJava 实现 Android 指纹识别代码 Android仿滴滴打车(滴滴UI)源码 Android高仿哔哩哔哩动 ...