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 ...
随机推荐
- UWP 记一次WTS 和 UCT翻车经历
这次翻车,真的,在网上绝对找不到回答的. 只有在WTS的Issues讨论中才找到,哈哈 不过这个应该比较少遇到吧,据我所知,提出Issue那个大胸弟和我都遇到了... 翻车具备的条件如下: 1. 使用 ...
- MyEclipse断点调试不可用解决办法
前言:MyEclipse中出现Debug调试不可用,断点处出现斜线.那么,如何解决此类问题? 1.打开myeclipse软件(版本不限) 2.设置断点,出现如下图所示情况,断点处出现斜线. 3.修改方 ...
- php的id加密
<?php/** * article url:http://kvz.io/blog/2009/06/10/create-short-ids-with-php-like-youtube-or-ti ...
- Android Studio|IntelliJ IDEA 上传代码到码云
码云 新建项目 Android Studio|IntelliJ IDEA 然后仓库就创建好了 此时左方文件应显示为红色 添加代码到git仓库 提交代码到git仓库 push等待被拒绝 拉取README ...
- Caffe Blob针对图像数据在内存中的组织方式
Caffe使用Blob结构在CNN网络中存储.传递数据.对于批量2D图像数据,Blob的维度为 图像数量N × 通道数C × 图像高度H × 图像宽度W 显然,在此种场景下,Blob使用4维坐标定位数 ...
- Netty源码分析第2章(NioEventLoop)---->第8节: 执行任务队列
Netty源码分析第二章: NioEventLoop 第八节: 执行任务队列 继续回到NioEventLoop的run()方法: protected void run() { for (;;) ...
- 读取classpath配置文件的方法
http://www.cnblogs.com/sprinng/p/5622600.html
- css 文字展示两行 其余的省略号显示
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- TeamWork#2,Week 5,Our Measurement of Contribution to the Team
经过了今天下午将近两个小时的激烈讨论,我们最终确定了我们的团队贡献分的分配方式,这种方式是我们团队都能接受的. 我们的分配方式一定程度上借鉴了valve公司的队友评估原则,但是又不单单是这样.我们的分 ...
- C++:模板——函数模板1
一.为什么使用函数模板 假设我们在程序中需要比较两个变量的大小,但变量的类型可能是int.float或者double,此时为了满足程序的要求我们可能会在程序中编写多个函数,如: //比较两个int型变 ...