题目链接

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

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

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pb(x) push_back(x)
  4. #define ll long long
  5. #define mk(x, y) make_pair(x, y)
  6. #define lson l, m, rt<<1
  7. #define mem(a) memset(a, 0, sizeof(a))
  8. #define rson m+1, r, rt<<1|1
  9. #define mem1(a) memset(a, -1, sizeof(a))
  10. #define mem2(a) memset(a, 0x3f, sizeof(a))
  11. #define rep(i, a, n) for(int i = a; i<n; i++)
  12. #define ull unsigned long long
  13. typedef pair<int, int> pll;
  14. const double PI = acos(-1.0);
  15. const double eps = 1e-;
  16. const int mod = 1e9+;
  17. const int inf = 1e4;
  18. const int dir[][] = { {-, }, {, }, {, -}, {, } };
  19. const int maxn = 2e5+;
  20. int num, q[maxn*], head[maxn*], dis[maxn*], s, t;
  21. struct node
  22. {
  23. int to, nextt, c;
  24. node(){}
  25. node(int to, int nextt, int c):to(to), nextt(nextt), c(c){}
  26. }e[maxn*];
  27. int bfs() {
  28. mem(dis);
  29. int st = , ed = ;
  30. dis[s] = ;
  31. q[ed++] = s;
  32. while(st<ed) {
  33. int u = q[st++];
  34. for(int i = head[u]; ~i; i = e[i].nextt) {
  35. int v = e[i].to;
  36. if(!dis[v]&&e[i].c) {
  37. dis[v] = dis[u]+;
  38. if(v == t)
  39. return ;
  40. q[ed++] = v;
  41. }
  42. }
  43. }
  44. return ;
  45. }
  46. int dfs(int u, int limit) {
  47. int cost = ;
  48. if(u == t)
  49. return limit;
  50. for(int i = head[u]; ~i; i = e[i].nextt) {
  51. int v = e[i].to;
  52. if(e[i].c&&dis[v] == dis[u]+) {
  53. int tmp = dfs(v, min(e[i].c, limit-cost));
  54. if(tmp>) {
  55. e[i].c -= tmp;
  56. e[i^].c += tmp;
  57. cost += tmp;
  58. if(cost == limit)
  59. break;
  60. } else {
  61. dis[v] = -;
  62. }
  63. }
  64. }
  65. return cost;
  66. }
  67. int dinic() {
  68. int ans = ;
  69. while(bfs()) {
  70. ans += dfs(s, inf);
  71. }
  72. return ans;
  73. }
  74. void add(int u, int v, int c) {
  75. e[num] = node(v, head[u], c); head[u] = num++;
  76. e[num] = node(u, head[v], c); head[v] = num++;
  77. }
  78. void init() {
  79. mem1(head);
  80. num = ;
  81. }
  82. int main()
  83. {
  84. int T, m, n, x, y, q, p, z;
  85. cin>>T;
  86. while(T--) {
  87. init();
  88. int sum = ;
  89. scanf("%d%d%d%d", &n, &m, &p, &q);
  90. s = p, t = q;
  91. while(m--) {
  92. scanf("%d%d%d", &x, &y, &z);
  93. add(x, y, z);
  94. sum += z;
  95. }
  96. int ans = dinic();
  97. if(ans == ) {
  98. cout<<"Inf"<<endl;
  99. continue;
  100. }
  101. sum -= ans;
  102. for(int i = ; i<num; i+=) {
  103. if(e[i].c == ) {
  104. e[i].c = ;
  105. e[i^].c = inf;
  106. } else if(e[i^].c==) {
  107. e[i].c = inf;
  108. e[i^].c = ;
  109. } else {
  110. e[i].c = e[i^].c = inf;
  111. }
  112. }
  113. ans = dinic();
  114. printf("%.2f\n", 1.0*sum/ans);
  115. }
  116. }

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. android webview点击返回键返回上一级activity

    android webview点击返回键返回上一个activity @Override public boolean onKeyDown(int keyCode, KeyEvent event) { ...

  2. D3学习教程

    [ D3.js 入门系列 ] 入门总结 | OUR D3.JS http://www.ourd3js.com/wordpress/?p=396

  3. NSString+URLEncoding

    NSString+URLEncoding.h #import <Foundation/Foundation.h> @interface NSString(URLEncoding) - (N ...

  4. 常用封装--Date篇--获取格式化的日期对象

    虽然日期对象可以使用new Date()来获取,但是对于其格式却必须进行相应的转换,才能成为开发者想要的格式. 这里提供了一个封装的方法,通过结合正则表达式的使用,达到了可以对时间对象进行处理,生成多 ...

  5. js基础——cssText

    以前,只知道设置css里的属性都是通过  元素.style.属性名 = 属性值  的方式,此时经常遇到的情况就是类似这样: var head= document.getElementById(&quo ...

  6. 幻世(OurDream)2D图形引擎易语言汉化版更新提示

    幻世引擎的易语言汉化专版到目前为止已经累积了多个BUG,其中多个BUG是影响引擎功能使用的问题,我将会在近期发布修复所有问题的更新版本(此更新版本同时也将会支持最新的对加入的粒子系统的支持),敬请各位 ...

  7. php不同形式的实现a-z的26个字母的输出

    直接上代码: for($i=ord('a'), $n=ord('z'); $i<=$n; $i++){ echo chr($i),PHP_EOL; } echo PHP_EOL; $char = ...

  8. visual studio 配置OpenGL环境

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

  9. 提示text还能输入多少字节

    1.添加jQuery自定义扩展 $(function($){ // tipWrap: 提示消息的容器 // maxNumber: 最大输入字符 $.fn.artTxtCount = function( ...

  10. CSliderCtrl鼠标点击精确定位

    实现CSliderCtrl的子类CXXCtrl 响应左键按下消息 ON_WM_LBUTTONDOWN() void CXXCtrl::OnLButtonDown(UINT nFlags, CPoint ...