ZOJ-2753
Time Limit: 15 Seconds Memory Limit: 32768 KB
Given an undirected graph, in which two vertexes can be connected by multiple edges, what is the min-cut of the graph? i.e. how many edges must be removed at least to partition the graph into two disconnected sub-graphes?
Input
Input contains multiple test cases. Each test case starts with two integers N and M (2<=N<=500, 0<=M<=N*(N-1)/2) in one line, where N is the number of vertexes. Following are M lines, each line contains M integers A, B and C (0<=A,B<N, A<>B, C>0), meaning that there C edges connecting vertexes A and B.
Output
There is only one line for each test case, which is the min-cut of the graph. If the graph is disconnected, print 0.
Sample Input
3 3
0 1 1
1 2 1
2 0 1
4 3
0 1 1
1 2 1
2 3 1
8 14
0 1 1
0 2 1
0 3 1
1 2 1
1 3 1
2 3 1
4 5 1
4 6 1
4 7 1
5 6 1
5 7 1
6 7 1
4 0 1
7 3 1
Sample Output
2
1
2
/**
最大流 == 最小割
**/
#include <iostream>
#include <string.h>
#include <cmath>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = ;
const ll maxw = ;
const ll inf = 1e17;
ll g[N][N], w[N];
int a[N], v[N], na[N];
ll mincut(int n) {
int i, j, pv, zj;
ll best = inf;
for(i = ; i < n; i ++) {
v[i] = i;
}
while(n > ) {
for(a[v[]] = , i = ; i < n; i ++) {
a[v[i]] = ;
na[i - ] = i;
w[i] = g[v[]][v[i]];
}
for(pv = v[], i = ; i < n; i ++) {
for(zj = -, j = ; j < n; j ++)
if(!a[v[j]] && (zj < || w[j] > w[zj])) {
zj = j;
}
a[v[zj]] = ;
if(i == n - ) {
if(best > w[zj]) {
best = w[zj];
}
for(i = ; i < n; i ++) {
g[v[i]][pv] = g[pv][v[i]] += g[v[zj]][v[i]];
}
v[zj] = v[--n];
break;
}
pv = v[zj];
for(j = ; j < n; j ++) if(!a[v[j]]) {
w[j] += g[v[zj]][v[j]];
}
}
}
return best;
}
int main()
{
int n, m, s;
while(~scanf("%d %d", &n, &m))
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
g[i][j] = ;
}
}
int u, v, w;
for(int i = ; i < m; i++)
{
scanf("%d %d %d", &u, &v, &w);
// u--;
// v--;
g[u][v] += w;
g[v][u] += w;
}
printf("%lld\n", mincut(n));
}
return ;
}
ZOJ-2753的更多相关文章
- ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)
题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
- zoj 1788 Quad Trees
zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
- ZOJ 1958. Friends
题目链接: ZOJ 1958. Friends 题目简介: (1)题目中的集合由 A-Z 的大写字母组成,例如 "{ABC}" 的字符串表示 A,B,C 组成的集合. (2)用运算 ...
随机推荐
- 【bzoj2743】[HEOI2012]采花 树状数组
题目描述 萧芸斓是Z国的公主,平时的一大爱好是采花. 今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花.花园足够大,容纳了n朵花,花有c种颜色(用整数1-c表示),且花是排成一排的,以便于公 ...
- NOIP2018普及&提高题解
第一次考$NOIP$的我已经自闭了 $CCF$告诉我们了一件事情,要对自己写的程序有信仰,相信$CCF$的数据是水的 普及组: 分数:$100+100+30+100=330$ $1.titile$: ...
- 调整KVM虚拟机硬盘大小
KVM虚拟机的硬盘映像默认存放在“/var/lib/libvirt/images/”中,先查看你的硬盘映像格式是不是RAW格式: qemu-img info /var/lib/libvirt/imag ...
- Widows与linux关于隐形文件和非隐形文件の对比
Widows与linux关于隐形文件和非隐形文件の对比 对于windows来说 ,它本身有一些隐藏文件,为了防止一些菜鸟不小心把电脑的主要文件删除,还有就是里面存放一些你不知道的后门. 对此我们一些同 ...
- maven的setting.xml文件中只配置本地仓库路径的方法
maven的setting.xml文件中只配置本地仓库路径的方法 即:settings标签下只有一个 localRepository标签,其他全部注释掉即可 <?xml version=&quo ...
- ACE中UDP通信
转载于:http://www.cnblogs.com/TianFang/archive/2006/12/07/585205.html udp是一种无连接的协议,提供无连接不可靠的服务. 在ace中,通 ...
- MYSQL性能察看
http://fengbin2005.iteye.com/blog/1580214 网上有很多的文章教怎么配置MySQL服务器,但考虑到服务器硬件配置的不同,具体应用的差别,那些文章的做法只能作为初步 ...
- MongoDB入门(4)- MongoDB日常操作
MongoDB客户端 MongoDB有很多客户端 MongoVue Robomongo MongoDB命令行 启动mongo shell 在windows下,双击mongo.exe可以启动mongo ...
- idea中设置springboot热部署
在idea中设置springboot热部署,项目修改的时候不用手动重启应用 1,pom中添加依赖 <dependency> <groupId>org.springframewo ...
- 删除linux上7天前后缀名.sql的文件
#!/bin/bash#delete the file of 7 days agofind /data/mysqlbackup/ -mtime +7 -name "*.sql" - ...