首页 技术 正文
技术 2022年11月17日
0 收藏 948 点赞 2,554 浏览 2196 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860