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

一开始把问题想简单了,以为网线可以随便接,其实是确定了u->v的= =

最小树形图,概念蛮好理解的,要学习的话

理论:http://hi.baidu.com/bin183/item/5d93ef69ceb541176895e682

代码标注的很详细:http://blog.csdn.net/hehedounima/article/details/9320173

其实,实质就是不断地缩点。需要注意的是选取以每个点为终点的最小边,以及重建图。

因为看人家缩点部分的代码写得略挫,于是我就写了个更挫的T^T——基于强连通缩点的。。细节在代码里已经标明

 #include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#define clr(a,m) memset(a,m,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std; const int MAXN=;
const int MAXM=;
const int INF =1e9; struct Edge{
int u,v,d,c;
}; int _n,m,w;
int root,u[MAXM],v[MAXM],d[MAXM],c[MAXM]; int head[MAXN],tol; int pre[MAXN],low[MAXN],sccno[MAXN],scc_cnt,dfs_clock;
int stk[MAXN],top; bool mark[MAXN];
Edge into[MAXN]; vector<Edge>edge;
vector<int>G[MAXN]; void init()
{
edge.clear();
rep(i,,_n-)//!!写成m-1,RE的泪啊
G[i].clear();
} void add(int u,int v,int d,int c)
{
edge.push_back((Edge){u,v,d,c});
int m=edge.size();
G[u].push_back(m-);
} void build()
{
rep(i,,m-)
add(u[i],v[i],d[i],c[i]);
} void rebuild()
{
rep(i,,m-){
int v=edge[i].v;
edge[i].u=sccno[edge[i].u];//自环会在处理into[]时省略
edge[i].v=sccno[edge[i].v];
if(edge[i].u!=edge[i].v)
edge[i].c-=into[v].c;
}
root=sccno[root];//更新root、n的值
_n=scc_cnt;
} void dfs(int v)//因为into[]里是以终点v记录,所以反向缩点
{
int u;
low[v]=pre[v]=dfs_clock++;
stk[top++]=v; u=into[v].u;
if(u!=root)//!!必不可少
if(!pre[u]){
dfs(u);
low[v]=min(low[v],low[u]);
}else if(!sccno[u])
low[v]=min(low[v],pre[u]); if(low[v]==pre[v]){
scc_cnt++;
do{
u=stk[--top];
sccno[u]=scc_cnt;
}while(u!=v);
}
} int find_scc()
{
scc_cnt=dfs_clock=;
clr(pre,);
clr(sccno,); top=;
rep(i,,_n)
if(!pre[i])
dfs(i);
return scc_cnt;
} bool DMST(int lim,int n)
{
_n=n; init();
build(); int cnt=;
while()
{
clr(mark,);
rep(i,,m-){
if(edge[i].d<lim||edge[i].u==edge[i].v)//注意自环
continue;
if(!mark[edge[i].v]){
into[edge[i].v]=(Edge){edge[i].u,edge[i].v,edge[i].d,edge[i].c};
mark[edge[i].v]=true;
}else if(into[edge[i].v].c>edge[i].c)
into[edge[i].v]=(Edge){edge[i].u,edge[i].v,edge[i].d,edge[i].c};
}
into[root]=(Edge){root,root,,};//处理根 rep(i,,_n){//root的序号随缩点改变
if(i==root)
continue;
if(!mark[i]){
return false;
}
cnt+=into[i].c;
}
if(cnt>w)
return false; if(find_scc()==_n)//若不成环
return true;
else
rebuild();
}
} int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
int up=,down=INF;
scanf("%d%d%d",&n,&m,&w);
root=; rep(i,,m-){
scanf("%d%d%d%d",&u[i],&v[i],&d[i],&c[i]);
u[i]++;v[i]++;//注意scc_cnt是从1开始的,意味着所有的点都是1~n
up=max(up,d[i]);
down=min(down,d[i]);
} if(!DMST(down,n)){
printf("streaming not possible.\n");
continue;
} int l=down,r=up;
while(l<r)
{
int x=l+(r-l+)/;
if(DMST(x,n))
l=x;
else
r=x-;
}
printf("%d kbps\n",l);
}
return ;
}
/*
3
7 15 29
0 1 1 9
0 4 1 5
1 3 1 9
1 2 1 3
2 1 1 7
2 6 1 6
2 5 1 9
3 0 1 3
3 2 1 8
3 5 1 5
4 3 1 4
5 4 1 3
5 6 1 4
6 2 1 4
6 5 1 8
*/

UVA 11865 Stream My Contest(最小树形图)的更多相关文章

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

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

  2. Stream My Contest UVA - 11865(带权最小树形图+二分最小值最大化)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  3. UVA 11865 Stream My Contest 组网 (朱刘算法,有向生成树,树形图)

    题意: 给n个点编号为0~n-1,0号点为根,给m条边(含自环,重边),每条边有个代价,也有带宽.给定c,问代价不超过c,树形图的最小带宽的最大值能达到多少? 思路: 点数才60,而带宽范围也不大,可 ...

  4. UVA 11183 Teen Girl Squad 最小树形图

    最小树形图模板题 #include <iostream> #include <algorithm> #include <cstdio> #include <c ...

  5. uvalive 11865 Stream My Contest

    题意: 有一个网络中心,和许多个城市,网络中心以及城市之间有若干条边,这些边有两个属性,最大带宽和修建费用. 现在要用最多不超过C的费用修建网络,使得每个城市都有网络连接,最大化最小带宽. 带宽限制是 ...

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

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

  7. Uva 11183 - Teen Girl Squad (最小树形图)

    Problem ITeen Girl Squad Input: Standard Input Output: Standard Output You are part of a group of n  ...

  8. UVA 6199 不定根最小树形图

    首先是最小树形图的介绍. 看这个博客.最小树形图 上面介绍的很详细了,我就讲一下这道题的题意. 首先给出一些二维点坐标,这些坐标之间构成一些有向图,根据题意,假设两个点a(x1 ,y1) ,b(x2 ...

  9. 【二分+最小树形图】UVA11865 比赛网络

    Description During 2009 and 2010 ICPC world finals, the contest was webcasted via world wide web. Se ...

随机推荐

  1. C+= concurrent_queue 线程安全测试

    更推荐使用:http://www.boost.org/doc/libs/1_56_0/doc/html/boost/lockfree/queue.html #include <include/t ...

  2. Ext学习-布局介绍

    1.目标    了解ExtJS中的关于布局和组建的相关原理,并学习相关的布局方式 2.内容   1.布局和组件的相关原理   2.常见的布局方式 3.学习流程    1.首先应该学习一下布局和组件的相 ...

  3. VIM Taglist安装配置和使用

    问题描述:            VIM  Taglist安装于配置 问题解决:             (1)安装Taglist包      (2)解压taglist压缩包         (3)将 ...

  4. PHP之implode与explode函数讲解

    implode (PHP 4, PHP 5) implode — 将一个一维数组的值转化为字符串 说明¶ string implode ( string $glue , array $pieces ) ...

  5. HDU1251 统计难题 Trie树

    题目很水,但毕竟是自己第一道的Trie,所以还是发一下吧.Trie的更多的应用慢慢学,AC自动机什么的也慢慢学.... #include<iostream> #include<cst ...

  6. POJ 3126 Prime Path(BFS求“最短路”)

    题意:给出两个四位数的素数,按如下规则变换,使得将第一位数变换成第二位数的花费最少,输出最少值,否则输出0. 每次只能变换四位数的其中一位数,使得变换后的数也为素数,每次变换都需要1英镑(即使换上的数 ...

  7. 入门视频采集与处理(BT656简介)

    入门视频采集与处理(BT656简介) http://ticktick.blog.51cto.com/823160/553535 1.  帧的概念(Frame) 一个视频序列是由N个帧组成的,采集图像的 ...

  8. React表单组件自定义-可控及不可控组件

    一.可控组件 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset=" ...

  9. python 有关矩阵行列的存取 np.array

    初始化 a = range() a = np.array(a) a = a.reshape(,) a [[ 0  1  2  3]  [ 4  5  6  7]  [ 8  9 10 11]  [12 ...

  10. !!无须定义配置文件中的每个变量的读写操作,以下代码遍历界面中各个c#控件,自动记录其文本,作为配置文件保存

    namespace PluginLib{    /// <summary>    /// 遍历控件所有子控件并初始化或保存其值    /// </summary>    pub ...