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 ...
随机推荐
- 关于selenium的智能等待页面加载的问题
我们经常会碰到用selenium操作页面上某个元素的时候,需要等待页面加载完成后,才能操作, 否则页面上的元素不存在,会抛出异常. 或者碰到AJAX异步加载,我们需要等待元素加载完成后,才能操作. 首 ...
- Python学习过程笔记整理(四)
变量作用域 -分类 -全局(global):在函数外部定义:整个全局范围都有效 -局部(local):在函数内部定义:仅在局部范围有效 -提升局部变量为全局变量 -使用global -globals, ...
- SourceTree跳过注册安装使用
%LocalAppData%\Atlassian\SourceTree\目录 创建一个accounts.json [ { "$id": "1", ...
- CentOS搭建Docker Hub私有仓库
docker pull registry拉取registry镜像 docker images查看镜像 docker run -d -p 5000:5000 -v /opt/data/registry: ...
- 用shell实现bat批处理的pause命令-追加改进
我参考了这个文章:用shell实现bat的pause http://linux-wiki.cn/wiki/zh-hans/%E7%94%A8shell%E5%AE%9E%E7%8E%B0bat%E7% ...
- python—索引与切片总结
python中索引与切片的熟练掌握对于字符串的操作很有帮助,梳理如下: (1)索引 S = 'hello world' 1)正向索引 正向索引从0开始,向右依次递增. 2)反向索引 反向索引从-1开始 ...
- 机器学习算法 --- Naive Bayes classifier
一.引言 在开始算法介绍之前,让我们先来思考一个问题,假设今天你准备出去登山,但起床后发现今天早晨的天气是多云,那么你今天是否应该选择出去呢? 你有最近这一个月的天气情况数据如下,请做出判断. 这个月 ...
- 数据库之python操作mysql
目录 一.pymysql 二.SQLAchemy 2.操作使用 (1)连接数据库 (2)执行原生SQL语句 (3)ORM操作-数据表操作 (4)ORM操作-数据行操作 (5)更多例子 一.pymysq ...
- spring--两个数据源模板
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-met ...
- JAVA自学日记——Part Ⅲ
终于来到了可视化窗口制作的部分了,从学习JAVA之前,到开始入手学习,一直到现在,都在盼望着有一天可以自己写出一款有界面而且是很美观的应用程序,今天算是一个真正开始的时间节点,值得纪念. 内容有很多, ...