在spoj上用题号找题就已经是手动二分了吧

把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流是否等于k来调整上下界。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N=505,inf=1e9;
int T,n,m,k,h[N],cnt,s,t,le[N],a[N*N][2],b[N];
struct qwe
{
int ne,to,va;
}e[N*N*2];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void add(int u,int v,int w)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].to=v;
e[cnt].va=w;
h[u]=cnt;
}
void ins(int u,int v,int w)
{//cout<<u<<" "<<v<<endl;
add(u,v,w);
add(v,u,0);
}
bool bfs()
{
memset(le,0,sizeof(le));
queue<int>q;
le[s]=1;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=h[u];i;i=e[i].ne)
if(!le[e[i].to]&&e[i].va>0)
{
le[e[i].to]=le[u]+1;
q.push(e[i].to);
}
}
return le[t];
}
int dfs(int u,int f)
{
if(u==t||!f)
return f;
int us=0;
for(int i=h[u];i&&us<f;i=e[i].ne)
if(le[e[i].to]==le[u]+1&&e[i].va>0)
{
int t=dfs(e[i].to,min(e[i].va,f-us));
e[i].va-=t;
e[i^1].va+=t;
us+=t;
}
return us;
}
int dinic()
{
int re=0;
while(bfs())
re+=dfs(s,inf);
return re;
}
bool ok(int p)
{
memset(h,0,sizeof(h));
cnt=1;
for(int i=1;i<=k;i++)
ins(s,b[i],1);
for(int i=1;i<=m;i++)
{
add(a[i][0],a[i][1],p);
add(a[i][1],a[i][0],p);
}
if(dinic()==k)
return 1;
return 0;
}
int main()
{
T=read();
while(T--)
{
n=read(),m=read(),k=read();//cout<<n<<" "<<m<<" "<<k<<endl;
s=0,t=1;
for(int i=1;i<=k;i++)
b[i]=read();
for(int i=1;i<=m;i++)
a[i][0]=read(),a[i][1]=read();
int l=0,r=n;
while(l<r)
{
int mid=(l+r)>>1;//cout<<l<<" "<<r<<" "<<mid<<endl;
if(ok(mid))
r=mid;
else
l=mid+1;
}
printf("%d\n",l);
}
return 0;
}

spoj 287 NETADMIN - Smart Network Administrator【二分+最大流】的更多相关文章

  1. SPOJ NETADMIN - Smart Network Administrator(二分)(网络流)

    NETADMIN - Smart Network Administrator #max-flow The citizens of a small village are tired of being ...

  2. [SPOJ 287] Smart Network Administrator 二分答案+网络流

    The citizens of a small village are tired of being the only inhabitants around without a connection ...

  3. SPOJ287 NETADMIN - Smart Network Administrator

    传送门[洛谷] 常见套路? 关键点连新建汇点 流量1 源点1 原图中的边 二分流量. 二分+判满流 做完了. 附代码. #include<cstdio> #include<cstri ...

  4. SPOJ287 Smart Network Administrator(最大流)

    题目大概是说,一个村庄有n间房子,房子间有m条双向路相连.1号房子有网络,有k间房子要通过与1号房子相连联网,且一条路上不能有同样颜色的线缆,问最少要用几种颜色的线缆. 二分枚举颜色个数,建立容量网络 ...

  5. Spoj-NETADMIN Smart Network Administrator

    The citizens of a small village are tired of being the only inhabitants around without a connection ...

  6. SPOJ 0287 Smart Network Administrator

    题目大意:一座村庄有N户人家.只有第一家可以连上互联网,其他人家要想上网必须拉一根缆线通过若干条街道连到第一家.每一根完整的缆线只能有一种颜色.网管有一个要求,各条街道内不同人家的缆线必须不同色,且总 ...

  7. SPOJ NETADMIN_Smart Network Administrator

    给一个图,某些点需要单独以某一种颜色的线连接到1点,问如何安排能够使得整个图颜色最多的一条路颜色最少. 显然,二分枚举然后加以颜色其实就是流量了,相当于对每条边限定一个当前二分的流量值,判断能否满流即 ...

  8. 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 ...

  9. hdu4560 不错的建图,二分最大流

    题意: 我是歌手 Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Subm ...

随机推荐

  1. Max Sum Plus Plus-HDU1024(dp)

    Problem Description Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To b ...

  2. hexo博客搭建及其美化

    ###1.GitHub创建个人仓库 登录到GitHub,如果没有GitHub帐号,使用你的邮箱注册GitHub帐号:Build software better, together 点击GitHub中的 ...

  3. 【Nginx】如何建立新连接

    处理新连接事件的回调函数是ngx_event_accept,原型如下: void ngx_event_accept(ngx_event_t *ev) 具体流程如下: 1)首先调用accept方法试图建 ...

  4. http://vdceye.com/ 全新页面上线

    vdceye manager home page

  5. 获取当前时间 YYYY-MM-DD

    1.函数封装 /** * 获取当前时间 * 格式YYYY-MM-DD */ Vue.prototype.getNowFormatDate = function() { var date = new D ...

  6. export setenv

    bash export LD_LIBRARY_PATH="../third_party/lib:$LD_LIBRARY_PATH" csh setenv LD_LIBRARY_PA ...

  7. 使用VLC搭建视频直播服务器

    去年我们信息之夜我们进行过视频直播服务,当时我们使用了WMS(Windows Media Server)实现了这个服务,但是编码是微软的WMV,因而像iPhone/Android这样的智能手机无法观看 ...

  8. 【转载】TCP和TCP/IP的区别

    TCP/IP协议(Transmission Control Protocol/Internet Protocol)叫做传输控制/网际协议, 又叫网络通讯协议,这个协议是Internet国际互联网络的基 ...

  9. 基于.net的分布式系统限流组件 C# DataGridView绑定List对象时,利用BindingList来实现增删查改 .net中ThreadPool与Task的认识总结 C# 排序技术研究与对比 基于.net的通用内存缓存模型组件 Scala学习笔记:重要语法特性

    基于.net的分布式系统限流组件   在互联网应用中,流量洪峰是常有的事情.在应对流量洪峰时,通用的处理模式一般有排队.限流,这样可以非常直接有效的保护系统,防止系统被打爆.另外,通过限流技术手段,可 ...

  10. iOS 开发小常识 开发笔记

    一   自定义push方法 /*  参数说明 *  controllerName : push的目标页 例:@“testcontroll”    ---注意不带.h *  isNibPage     ...