UVA 11865 Stream My Contest (二分+最小树形图)
题意:给定一个网络,一个服务器,其他的是客户机,有 m 条连线,每条有一个带宽和花费(单向边),让你用不超过 c 的花费,使得 0 到 所有的机器都能到达,并且使得最小带宽最大。
析:很明显是二分题,然后在判断,就是保证从 0 到所有的点都是通路,这就是最小树形图,直接上模板就好。
代码如下;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 60 + 10;
const LL mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
struct Edge{
int u, v, cost;
};
Edge edge[10050], a[10050];
int b[10050];
int pre[maxn], id[maxn], vis[maxn], in[maxn]; int solve(int rt, int n, int m){
int ans = 0;
while(true){
ms(in, INF);
FOR(i, 0, m) if(edge[i].u != edge[i].v && edge[i].cost < in[edge[i].v]){
pre[edge[i].v] = edge[i].u;
in[edge[i].v] = edge[i].cost;
}
FOR(i, 0, n) if(i != rt && in[i] == INF) return -1;
int tn = 0;
ms(id, -1); ms(vis, -1);
in[rt] = 0;
for(int i = 0; i < n; ++i){
ans += in[i];
int v = i;
while(vis[v] != i && id[v] == -1 && v != rt){
vis[v] = i;
v = pre[v];
}
if(v != rt && id[v] == -1){
for(int u = pre[v]; u != v; u = pre[u]) id[u] = tn;
id[v] = tn++;
}
}
if(tn == 0) break;
FOR(i, 0, n) if(id[i] == -1) id[i] = tn++;
for(int i = 0; i < m; ){
int v = edge[i].v;
edge[i].u = id[edge[i].u];
edge[i].v = id[edge[i].v];
if(edge[i].u != edge[i].v) edge[i++].cost -= in[v];
else swap(edge[i], edge[--m]);
}
n = tn;
rt = id[rt];
}
return ans;
} bool judge(int mid, int c){
int cnt = 0;
for(int i = 0; i < m; ++i)
if(b[i] >= mid) edge[cnt++] = a[i];
int ans = solve(0, n, cnt);
if(ans == -1) return false;
bool ok = ans <= c;
return ans <= c;
} int main(){
int T; cin >> T;
while(T--){
int c;
scanf("%d %d %d", &n, &m, &c);
int l = 1, r = 0;
for(int i = 0; i < m; ++i) scanf("%d %d %d %d", &a[i].u, &a[i].v, &b[i], &a[i].cost), r = max(r, b[i]);
if(!judge(0, c)){ puts("streaming not possible."); continue; }
while(l <= r){
int m = l + r >> 1;
if(judge(m, c)) l = m + 1;
else r = m - 1;
}
printf("%d kbps\n", l - 1);
}
return 0;
}
UVA 11865 Stream My Contest (二分+最小树形图)的更多相关文章
- UVA 11865 Stream My Contest(最小树形图)
题意:N台机器,M条有向边,总资金C,现要到搭建一个以0号机(服务器)为跟的网路,已知每条网线可以把数据从u传递到v,其带宽为d,花费为c,且d越大,传输速度越快,问能够搭建的传输速度最快的网络d值是 ...
- UVA 11865 Stream My Contest 组网 (朱刘算法,有向生成树,树形图)
题意: 给n个点编号为0~n-1,0号点为根,给m条边(含自环,重边),每条边有个代价,也有带宽.给定c,问代价不超过c,树形图的最小带宽的最大值能达到多少? 思路: 点数才60,而带宽范围也不大,可 ...
- 【二分+最小树形图】UVA11865 比赛网络
Description During 2009 and 2010 ICPC world finals, the contest was webcasted via world wide web. Se ...
- uvalive 11865 Stream My Contest
题意: 有一个网络中心,和许多个城市,网络中心以及城市之间有若干条边,这些边有两个属性,最大带宽和修建费用. 现在要用最多不超过C的费用修建网络,使得每个城市都有网络连接,最大化最小带宽. 带宽限制是 ...
- Uva 11183 - Teen Girl Squad (最小树形图)
Problem ITeen Girl Squad Input: Standard Input Output: Standard Output You are part of a group of n ...
- 【UVA 11865】 Stream My Contest (二分+MDST最小树形图)
[题意] 你需要花费不超过cost元来搭建一个比赛网络.网络中有n台机器,编号0~n-1,其中机器0为服务器,其他机器为客户机.一共有m条可以使用的网线,其中第i条网线的发送端是机器ui,接收端是机器 ...
- UVA-11865 Stream My Contest (朱-刘 算法+二分)
题目大意:有一张n个顶点,m条边的有向图,根节点为0.每条边有两个权值,一个是费用c,一个是长度b.问在总费用不超过cost的情况下选出若干条边,使得n个点连通时的边的最短长度的最大值是多少. 题目分 ...
- UVA 11183 Teen Girl Squad 最小树形图
最小树形图模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <c ...
- UVA 6199 不定根最小树形图
首先是最小树形图的介绍. 看这个博客.最小树形图 上面介绍的很详细了,我就讲一下这道题的题意. 首先给出一些二维点坐标,这些坐标之间构成一些有向图,根据题意,假设两个点a(x1 ,y1) ,b(x2 ...
随机推荐
- 解决crontab不加载环境变量问题
公司需要做异构库数据同步,由于之前实际使用过,且字段类型也兼容,满足业务场景,使用了阿里开源数据同步工具:datax,服务器上crontab定时脚本执行. 由于crontab只加载/ect/envir ...
- IE8 focus 失效解决方案
这几天遇到两个在IE8下focus失效的非常奇怪的问题,当然这个是指JS函数: document.getElementById("id").focus(); 或者 $(" ...
- 大数据框架hadoop的序列化机制
Java内建序列化机制 在Windows系统上序列化的Java对象,可以在UNIX系统上被重建出来,不需要担心不同机器上的数据表示方法,也不需要担心字节排列次序. 在Java中,使一个类的实例可被序列 ...
- SpringBoot2.0 url中出现特殊符号「带括号{}'"等等」时会抛出400错误
访问 http://127.0.0.1:8080/api?method=taxiong.goods.list¶ms={"page":1,"pageSize ...
- 【转】MySQL存储过程中使用动态行转列
MySQL存储过程中使用动态行转列 最近做项目关于数据报表处理,然而数据库存储格式和报表展现形式不同,需要进行一下行转列的操作,在做上一个项目的时候也看了一下,但是后来换了读取方式,也就没深入研究这个 ...
- 配置 host only 后 nat不能上网了
如果只有nat 网关为nat 中设置的网关 eth0 启动第二块网卡host_only 网关就变成了 host_only中的网关 eth1 解决放法 route -n 看启用的是哪个网关 [roo ...
- Tensorflow笔记——神经网络图像识别(四)搭建模块化的神经网络八股(正则化,指数衰减学习率,滑动平均等优化)
实战案例: 数据X[x0,x1]为正太分布随机点, 标注Y_,当x0*x0+x1*x1<2时,y_=1(红),否则y_=0(蓝) 建立三个.py文件 1. generateds.py生成数据 ...
- linux中强大的screen命令
今天发现了一个“宝贝”,就是Linux的screen命令,对于远程登录来说,不仅提供了类似于nohup的功能,而且提供了我非常喜欢的“多个桌面”的功能. 平常开一个putty远程登录,经常需要在两个程 ...
- JMS消息模型
消息机制: 系统之间通信的中介,作为一台单独的服务器部署,大多数使用多个系统之间协作,是系统解耦的常见解决方案. 基于CS架构 作用:多个系统之间解耦,项目可以分开开发,满足显示的高可用(也可以说是异 ...
- solr删除全部索引数据
SOLR 删除全部索引数据: <delete><query>*:*</query></delete><commit/>