题目链接

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

先求一遍最小割, 然后把所有割边的权值变为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. OCP-1Z0-053-V12.02-501题 【转】

    http://blog.csdn.net/rlhua/article/details/12225237 501.Note the output of the following query; SQL& ...

  2. PHP Curl CURLOPT_POSTFIELDS 1024

    resolve : curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); url: http://www.laruence.com/2011/ ...

  3. CircleImageView 圆形图片头像实现

    package com.view.drop; import android.content.Context; import android.content.res.TypedArray; import ...

  4. 练习-checkbox 全选 ,反选, 单选,以及取值

    1.方法1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...

  5. js previousSibling兼容使用方法

    使用previousSibling的时候发现当前元素跟上一个元素之间有空格就不获取不到对象, 查资料才知道除了ie外js的previousSibling获取的对象包括空格! 兼容方法如下: funct ...

  6. 如何获取fragment里的控件

    不能在onCreate函数中获取控件,以为fragment还没有start,你可以在onStart函数中获取: @Overrideprotected void onStart() { super.on ...

  7. binwalk windows安装和使用方法

    binwalk是一个文件的分析工具,旨在协助研究人员对文件进行分析,提取及逆向工程.简单易用,完全自动化脚本,并通过自定义签名,提取规则和插件模块,还重要一点的是可以轻松地扩展. 以上是binwalk ...

  8. python 装饰器、内部函数、闭包简单理解

    python内部函数.闭包共同之处在于都是以函数作为参数传递到函数,不同之处在于返回与调用有所区别. 1.python内部函数 python内部函数示例: def test(*args): def a ...

  9. visual studio 配置OpenGL环境

    首先在网上下载一个GLUT工具包. glut.zip,大约一百多kb. 解压之后得到这么几个文件: 将glut.h复制到C:\Program Files (x86)\Microsoft Visual ...

  10. 搞了一个独立博客,请各位光临pingworld.cn

    嘿嘿,每次在一个大网站上建立自己的博客后总是没有动力持续更新下去,回想其原因很大是因为没有一个自己的地盘,懒得维护!还有一个原因就是自己也没有什么干货值得跟大家分享. 随着工作的时日见长,有了各种各样 ...