SPOJ NETADMIN_Smart Network Administrator
给一个图,某些点需要单独以某一种颜色的线连接到1点,问如何安排能够使得整个图颜色最多的一条路颜色最少。
显然,二分枚举然后加以颜色其实就是流量了,相当于对每条边限定一个当前二分的流量值,判断能否满流即可。
召唤代码君:
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 555
#define maxm 333333
using namespace std; const int inf=~0U>>;
int to[maxm],next[maxm],c[maxm],first[maxm],edge;
int tag[maxn],d[maxn],TAG=;
int Q[maxn],bot,top;
bool can[maxn];
int n,m,k,T,h,s,t,house,ans,boder; void addedge(int U,int V)
{
edge++;
to[edge]=V,c[edge]=,next[edge]=first[U],first[U]=edge;
edge++;
to[edge]=U,c[edge]=,next[edge]=first[V],first[V]=edge;
} void _input()
{
scanf("%d%d%d",&n,&m,&k);
edge=-;
for (int i=; i<=n; i++) first[i]=-;
s=,t=,house=k;
while (k--)
{
scanf("%d",&h);
addedge(h,t);
}
boder=edge;
while (m--)
{
scanf("%d%d",&k,&h);
addedge(k,h);
}
} bool bfs()
{
Q[bot=top=]=t,d[t]=,can[t]=false,tag[t]=++TAG;
while(bot<=top)
{
int cur=Q[bot++];
for (int i=first[cur]; i!=-; i=next[i])
{
if (c[i^]> && tag[to[i]]!=TAG)
{
tag[to[i]]=TAG,Q[++top]=to[i];
d[to[i]]=d[cur]+,can[to[i]]=false;
if (to[i]==s) return true;
}
}
}
return false;
} int dfs(int cur,int num)
{
if (cur==t) return num;
int tmp=num,k;
for (int i=first[cur]; i!=-; i=next[i])
if (c[i]> && d[to[i]]==d[cur]- && tag[to[i]]==TAG && !can[to[i]])
{
k=dfs(to[i],min(num,c[i]));
if (k) num-=k,c[i]-=k,c[i^]+=k;
if (num==) break;
}
if (num) can[cur]=true;
return tmp-num;
} bool check(int x)
{
for (int i=; i<=boder; i++) c[i]=;
for (int i=boder+; i<=edge; i++) c[i]=x;
for ( ans=; bfs(); ) ans+=dfs(s,inf);
return ans>=house;
} int main()
{
scanf("%d",&T);
while (T--)
{
_input();
int l=,r=n,mid;
while (l<r)
{
mid=(l+r)>>;
if (check(mid)) r=mid;
else l=mid+;
}
printf("%d\n",l);
}
return ;
}
SPOJ NETADMIN_Smart Network Administrator的更多相关文章
- [SPOJ 287] Smart Network Administrator 二分答案+网络流
The citizens of a small village are tired of being the only inhabitants around without a connection ...
- SPOJ NETADMIN - Smart Network Administrator(二分)(网络流)
NETADMIN - Smart Network Administrator #max-flow The citizens of a small village are tired of being ...
- Spoj-NETADMIN Smart Network Administrator
The citizens of a small village are tired of being the only inhabitants around without a connection ...
- routing decisions based on paths, network policies, or rule-sets configured by a network administrator
https://en.wikipedia.org/wiki/Border_Gateway_Protocol Border Gateway Protocol (BGP) is a standardize ...
- spoj 287 NETADMIN - Smart Network Administrator【二分+最大流】
在spoj上用题号找题就已经是手动二分了吧 把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流 ...
- SPOJ 0287 Smart Network Administrator
题目大意:一座村庄有N户人家.只有第一家可以连上互联网,其他人家要想上网必须拉一根缆线通过若干条街道连到第一家.每一根完整的缆线只能有一种颜色.网管有一个要求,各条街道内不同人家的缆线必须不同色,且总 ...
- internet connection sharing has been disabled by the network administrator
Start > Run > gpedit.msc Locate; Computer Configuration/Administrative Templates/Network/Netwo ...
- SPOJ287 Smart Network Administrator(最大流)
题目大概是说,一个村庄有n间房子,房子间有m条双向路相连.1号房子有网络,有k间房子要通过与1号房子相连联网,且一条路上不能有同样颜色的线缆,问最少要用几种颜色的线缆. 二分枚举颜色个数,建立容量网络 ...
- SPOJ287 NETADMIN - Smart Network Administrator
传送门[洛谷] 常见套路? 关键点连新建汇点 流量1 源点1 原图中的边 二分流量. 二分+判满流 做完了. 附代码. #include<cstdio> #include<cstri ...
随机推荐
- 程序员 vs HR(皮这么一下很开心)
最近网络上一段 HR VS 程序员 的表情包火了 来来来 我们近距离感受下 来源|网络:http://t.cn/RuTKC8B 哈哈哈!大家可以留言说说你们面试时候的趣事 更多内容关注公众号:51re ...
- linux下的静态库与动态库
目录 静态库 定义: 生成及使用方法: 静态库的优缺点 动态库 定义: 生成及使用方法: 动态库优缺点: 静态库 先说说我们为什么需要库? 当有些代码我们大量会在程序中使用比如(scanf,print ...
- Genymotion模拟器安装问题及解决(启动失败,模拟器不能联网)
安装Genymotion模拟器安装后启动不了,报错: 百度的解决方法是打开VMVBirtualox选中自己的设备点击设置—常规—将版本设置为图中箭头所指的: 但是我这样做的时候发现我的下拉列表中没有6 ...
- LintCode——颜色分类
颜色分类:给定一个包含红,白,蓝且长度为 n 的数组,将数组元素进行分类使相同颜色的元素相邻,并按照红.白.蓝的顺序进行排序. 我们可以使用整数 0,1 和 2 分别代表红,白,蓝. 注意事项: 不能 ...
- iOS分类Category探索
什么是Category? Category是Objective-C 2.0之后添加的语言特性,Category的主要作用是为已经存在的类添加方法,一般称为分类,文件名格式是"NSObject ...
- linux执行命令返回码释义
Linux 操作系统错误代码解释 0.错误代码1-10 OS error code 0: Success 操作系统错误代码0:成功 OS error code 1: Operation not per ...
- Windows下的ROUGE文本测评工具基本安装
需要的安装包: rouge1.5.5:https://pan.baidu.com/s/1B7-LYn1lZKC8f51yXxNK9w Strawberry Perl :http://strawberr ...
- Python从菜鸟到高手:格式化字符串
1. 字符串格式化基础 字符串格式化相当于字符串模板.也就是说,如果一个字符串有一部分是固定的,而另一部分是动态变化的,那么就可以将固定的部分做成模板,然后那些动态变化的部分使用字符串格式化操作符(% ...
- decode 函数及其用法
http://blog.csdn.net/oscar999/article/details/18399177
- 论如何制做一个工程APP的测试内容
测试一般在软件开发过程中就已经开始进行了,测试越早.发现问题解决他的方案成本就越小.测试按照类型来区分可以划分为:单元测试,集成测试,系统测试.而OCUNIT是XCODE自带的单元测试工具.需要建立新 ...