zoj 3792 Romantic Value
求最小割的值, 以及割边最少的情况的边数。
先求一遍最小割, 然后把所有割边的权值变为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的更多相关文章
- ZOJ 3792 Romantic Value 最小割(最小费用下最小边数)
求最小割及最小花费 把边权c = c*10000+1 然后跑一个最小割,则flow / 10000就是费用 flow%10000就是边数. 且是边数最少的情况.. #include<stdio. ...
- 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 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...
随机推荐
- android webview点击返回键返回上一级activity
android webview点击返回键返回上一个activity @Override public boolean onKeyDown(int keyCode, KeyEvent event) { ...
- D3学习教程
[ D3.js 入门系列 ] 入门总结 | OUR D3.JS http://www.ourd3js.com/wordpress/?p=396
- NSString+URLEncoding
NSString+URLEncoding.h #import <Foundation/Foundation.h> @interface NSString(URLEncoding) - (N ...
- 常用封装--Date篇--获取格式化的日期对象
虽然日期对象可以使用new Date()来获取,但是对于其格式却必须进行相应的转换,才能成为开发者想要的格式. 这里提供了一个封装的方法,通过结合正则表达式的使用,达到了可以对时间对象进行处理,生成多 ...
- js基础——cssText
以前,只知道设置css里的属性都是通过 元素.style.属性名 = 属性值 的方式,此时经常遇到的情况就是类似这样: var head= document.getElementById(&quo ...
- 幻世(OurDream)2D图形引擎易语言汉化版更新提示
幻世引擎的易语言汉化专版到目前为止已经累积了多个BUG,其中多个BUG是影响引擎功能使用的问题,我将会在近期发布修复所有问题的更新版本(此更新版本同时也将会支持最新的对加入的粒子系统的支持),敬请各位 ...
- php不同形式的实现a-z的26个字母的输出
直接上代码: for($i=ord('a'), $n=ord('z'); $i<=$n; $i++){ echo chr($i),PHP_EOL; } echo PHP_EOL; $char = ...
- visual studio 配置OpenGL环境
首先在网上下载一个GLUT工具包. glut.zip,大约一百多kb. 解压之后得到这么几个文件: 将glut.h复制到C:\Program Files (x86)\Microsoft Visual ...
- 提示text还能输入多少字节
1.添加jQuery自定义扩展 $(function($){ // tipWrap: 提示消息的容器 // maxNumber: 最大输入字符 $.fn.artTxtCount = function( ...
- CSliderCtrl鼠标点击精确定位
实现CSliderCtrl的子类CXXCtrl 响应左键按下消息 ON_WM_LBUTTONDOWN() void CXXCtrl::OnLButtonDown(UINT nFlags, CPoint ...