Description

During 2009 and 2010 ICPC world finals, the contest was webcasted via world wide web. Seeing this, some contest organizers from Ajobdesh decided that, they will provide a live stream of their contests to every university in Ajobdesh. The organizers have decided that, they will provide best possible service to them. But there are two problems: 1. There is no existing network between universities. So, they need to build a new network. However, the maximum amount they can spend on building the network is C. 2. Each link in the network has a bandwidth. If, the stream’s bandwidth exceeds any of the link’s available bandwidth, the viewers, connected through that link can’t view the stream. Due to the protocols used for streaming, a viewer can receive stream from exactly one other user (or the server, where the contest is organized). That is, if you have two 128kbps links, you won’t get 256kbps bandwidth, although, if you have a stream of 128kbps, you can stream to any number of users at that bandwidth. Given C, you have to maximize the minimum bandwidth to any user.

Solution

二分最小带宽,求最小树形图看是否超过C。

Code

写这题各种犯逗,简直感动不能多说。

 #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=,maxm=1e4+; struct edge{
int v,u,b,c;
bool operator<(const edge&a)
const{return b<a.b;}
}E[maxm],e[maxm];
int in[maxn],pre[maxn],vis[maxn],id[maxn];
int N,M,C; int work(int n,int m,int lim){
memcpy(e,E,sizeof(e));
long long ret=;
int root=;
if(!lim) lim=; while(){
memset(in,,sizeof(in));
int inf=in[];
for(int i=lim;i<=m;i++){
int u=e[i].u,v=e[i].v;
if(u!=v&&e[i].c<in[v]){
in[v]=e[i].c;
pre[v]=u;
}
}
for(int i=;i<=n;i++)
if(i!=root&&in[i]==inf) return ; in[root]=;
int cnt=;
memset(id,,sizeof(id));
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++){
ret+=in[i];
if(!vis[i]){
int u=i;
while(u!=root&&!vis[u]){
vis[u]=i;
u=pre[u];
}
if(vis[u]==i){
++cnt;
int v=u;
do{
id[v]=cnt;
v=pre[v];
}while(v!=u);
}
}
} if(!cnt) break;
for(int i=;i<=n;i++)
if(!id[i]) id[i]=++cnt;
for(int i=lim;i<=m;i++){
int v=e[i].v;
e[i].u=id[e[i].u];
e[i].v=id[e[i].v];
if(e[i].u!=e[i].v)
e[i].c-=in[v];
}
n=cnt;
root=id[root];
}
if(ret<=C) return ;
return ;
} int main(){
int T;
scanf("%d",&T); while(T--){
scanf("%d%d%d",&N,&M,&C);
for(int i=;i<=M;i++){
scanf("%d%d%d%d",&E[i].u,&E[i].v,&E[i].b,&E[i].c);
E[i].u++,E[i].v++;
}
sort(E+,E+M+); int l=,r=M;
while(l<r){
int mid=(l+r+)>>;
if(work(N,M,mid)) l=mid;
else r=mid-;
} if(!l) printf("streaming not possible.\n");
else printf("%d kbps\n",E[l].b);
}
return ;
}

【二分+最小树形图】UVA11865 比赛网络的更多相关文章

  1. UVA 11865 Stream My Contest (二分+最小树形图)

    题意:给定一个网络,一个服务器,其他的是客户机,有 m 条连线,每条有一个带宽和花费(单向边),让你用不超过 c 的花费,使得 0 到 所有的机器都能到达,并且使得最小带宽最大. 析:很明显是二分题, ...

  2. 【UVA 11865】 Stream My Contest (二分+MDST最小树形图)

    [题意] 你需要花费不超过cost元来搭建一个比赛网络.网络中有n台机器,编号0~n-1,其中机器0为服务器,其他机器为客户机.一共有m条可以使用的网线,其中第i条网线的发送端是机器ui,接收端是机器 ...

  3. HDU 4966 GGS-DDU(最小树形图)

    n个技能,每个技能有0-a[i]的等级,m个课程,每个课程需要前置技能c[i]至少达到lv1[i]等级,效果是技能d[i]达到lv2[i]等级,花费w[i]. 输出最小花费使得全技能满级(初始全技能0 ...

  4. UVA 11865 Stream My Contest(最小树形图)

    题意:N台机器,M条有向边,总资金C,现要到搭建一个以0号机(服务器)为跟的网路,已知每条网线可以把数据从u传递到v,其带宽为d,花费为c,且d越大,传输速度越快,问能够搭建的传输速度最快的网络d值是 ...

  5. POJ 3164 Command Network ( 最小树形图 朱刘算法)

    题目链接 Description After a long lasting war on words, a war on arms finally breaks out between littlek ...

  6. 最小树形图(poj3164)

    Command Network Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 12834   Accepted: 3718 ...

  7. bzoj4349: 最小树形图

    最小树形图模板题…… 这种\(O(nm)\)的东西真的能考到么…… #include <bits/stdc++.h> #define N 60 #define INF 1000000000 ...

  8. hdu 4966 GGS-DDU (最小树形图)

    比较好的讲解:http://blog.csdn.net/wsniyufang/article/details/6747392 view code//首先为除根之外的每个点选定一条入边,这条入边一定要是 ...

  9. hdu3072 强连通+最小树形图

    题意:有一个人他要把一个消息通知到所有人,已知一些通知关系:A 能通知 B,需要花费 v,而又知道,如果某一个小团体,其中的成员相互都能直接或间接通知到,那么他们之间的消息传递是不需要花费的,现在问这 ...

随机推荐

  1. 管理xcode插件

    1.打开终端 2.输入     open ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins 3.出现 4.想删除那个就随意吧 ...

  2. 万水千山ABP - 时区问题

    关于时间和时区问题,后面的参考文章中有详细的描述. 我遇到的问题是: 在MVC视图页面中,显示记录的生成时间 CreationTime <div> @Model.CreationTime ...

  3. tomcat启动非常慢;连接oracle数据库失败,jdbc错误日志提示connection reset;测试主机间网络互通及数据库端口都正常

      [判断确认:这时候大家可能要去检查一下/dev/random 这个设备档案.可以用cat /dev/random 来看它的内容,如果你发现他一直没显示任何内容﹝可能是乱码数字之类的﹞,那就是它出问 ...

  4. Github Page 绑定域名

    http://kyle.xlau.org/posts/github-cname.html CNAME 创建一个CNAME文件,内容是你的域名,如: xlau.org 然后把此文件添加到Github仓库 ...

  5. The note of Developing Innovative Ideas for New Companies Course

    This course is free on the Coursera Site,But it only has English version Threee pieces of the course ...

  6. DUIR Framework 相关技术介绍

    开发者在搭建界面自动化测试框架时,又或者在开发界面自动化控制的机器人时,往往需要对界面进行自动化的程序控制.而现在公司内部使用的杜尔自动化框架,就是一个封装了界面自动化控制逻辑的程序框架.基于该框架, ...

  7. memcached server install(WSL)

    prepare:0) libevent-dev1) libseccomp-dev2) build-essential3) automake install: https://www.liquidweb ...

  8. log4j配置及使用

    一.使用方法: 1.将log4j.properties放到你创建项目的src中 2.引入log4j.jar import org.apache.log4j.*; public class log4jT ...

  9. mysql-高级操作

    主键冲突 主键冲突的时候,可以选择更新或者替换进行处理 更新 主键冲突,更新操作. Insert into 表名[(字段列表:包含主键)] values(值列表) on duplicate key u ...

  10. [Java算法分析与设计]--线性结构与顺序表(List)的实现应用

    说到线性结构,我们应该立马能够在脑子里蹦出"Array数组"这个词.在Java当中,数组和对象区别基本数据类型存放在堆当中.它是一连串同类型数据存放的一个整体.通常我们定义的方式为 ...