题目链接

求最小割的值, 以及割边最少的情况的边数。

先求一遍最小割, 然后把所有割边的权值变为1, 其他边变成inf, 在求一遍最小割, 此时求出的就是最少边数。

Inf打成inf  WA了好几发............

 #include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = 1e4;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 2e5+;
int num, q[maxn*], head[maxn*], dis[maxn*], s, t;
struct node
{
int to, nextt, c;
node(){}
node(int to, int nextt, int c):to(to), nextt(nextt), c(c){}
}e[maxn*];
int bfs() {
mem(dis);
int st = , ed = ;
dis[s] = ;
q[ed++] = s;
while(st<ed) {
int u = q[st++];
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(!dis[v]&&e[i].c) {
dis[v] = dis[u]+;
if(v == t)
return ;
q[ed++] = v;
}
}
}
return ;
}
int dfs(int u, int limit) {
int cost = ;
if(u == t)
return limit;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(e[i].c&&dis[v] == dis[u]+) {
int tmp = dfs(v, min(e[i].c, limit-cost));
if(tmp>) {
e[i].c -= tmp;
e[i^].c += tmp;
cost += tmp;
if(cost == limit)
break;
} else {
dis[v] = -;
}
}
}
return cost;
}
int dinic() {
int ans = ;
while(bfs()) {
ans += dfs(s, inf);
}
return ans;
}
void add(int u, int v, int c) {
e[num] = node(v, head[u], c); head[u] = num++;
e[num] = node(u, head[v], c); head[v] = num++;
}
void init() {
mem1(head);
num = ;
}
int main()
{
int T, m, n, x, y, q, p, z;
cin>>T;
while(T--) {
init();
int sum = ;
scanf("%d%d%d%d", &n, &m, &p, &q);
s = p, t = q;
while(m--) {
scanf("%d%d%d", &x, &y, &z);
add(x, y, z);
sum += z;
}
int ans = dinic();
if(ans == ) {
cout<<"Inf"<<endl;
continue;
}
sum -= ans;
for(int i = ; i<num; i+=) {
if(e[i].c == ) {
e[i].c = ;
e[i^].c = inf;
} else if(e[i^].c==) {
e[i].c = inf;
e[i^].c = ;
} else {
e[i].c = e[i^].c = inf;
}
}
ans = dinic();
printf("%.2f\n", 1.0*sum/ans);
}
}

zoj 3792 Romantic Value的更多相关文章

  1. ZOJ 3792 Romantic Value 最小割(最小费用下最小边数)

    求最小割及最小花费 把边权c = c*10000+1 然后跑一个最小割,则flow / 10000就是费用 flow%10000就是边数. 且是边数最少的情况.. #include<stdio. ...

  2. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  3. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  4. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  5. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  6. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  7. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  8. ZOJ Problem Set - 1001 A + B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...

  9. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

随机推荐

  1. 在 PL/SQL Developer 中执行SQL文件的方法

    打开 command Window SQL> @'D:\My Documents\Downloads\bde_chk_cbo.sql'; 整个路径及文件两边要有单引号哦!

  2. JAVA设计原则

      1.单一职责规则(SRP):有且仅有一个原因引起类的变化. 2.依赖倒置规则(DIP): 高层模块不应该依赖底层模块,两者都用依赖接口: 接口不依赖细节: 细节依赖接口. 3.接口隔离规则:类间的 ...

  3. C语言版推箱子

    推箱子源代码初步: #include<stdio.h> #include<conio.h> #include<stdlib.h> #define boolean i ...

  4. group_concat 使用

    Mysql中使用group_concat时,出现Row 1 was cut by GROUP_CONCAT()异常. group_concat默认的最大拼接长度,是1024. 把所有子节点的ID,用逗 ...

  5. perl正则表达式第一周笔记

    正则表达式基础 ^ 行首标志 $ 行末标志 如^cat即一整行只有cat这个单词,^则是一个空行 [  ] 字符组,用来匹配若干字符之一 如gr[ae]y,即grey或者gray - 在字符组内部,字 ...

  6. crt 糟心的配置

    每次要下载安装crt就要捣鼓半天,各种注册机下来各种问题,顺手记录下刚打通的一个 1.crt 下载 网上看了一遍博客: SecureCRT 7.3.4破解版(含注册机), 下载下来后里面其实是不含注册 ...

  7. Traveling

    Problem J: Traveling Time Limit: 1 Sec  Memory Limit: 32 MB Description SH likes traveling around th ...

  8. s3c6410学习笔记-烧写uboot+构建文件系统

    一.进入目录 #cd u-boot-1.1.6_sndk6410 二.SD卡 make clean make distclean vim Makefile                       ...

  9. 【Chromium中文文档】插件架构

    插件架构 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Plugin_A ...

  10. linux基础--chkconfig 详解

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...