SPOJ287 NETADMIN - Smart Network Administrator
传送门[洛谷]
常见套路?
关键点连新建汇点 流量1 源点1 原图中的边 二分流量。
二分+判满流
做完了。
附代码。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define inf 20021225
#define ll long long
#define mxm 251000
#define mxn 510
using namespace std;
struct edge{int to,lt,f;}e[mxm];
int in[mxn],cnt,dep[mxn],s,t;queue<int> que;
void add(int x,int y,int f)
{
e[++cnt].to=y;e[cnt].lt=in[x];in[x]=cnt;e[cnt].f=f;
e[++cnt].to=x;e[cnt].lt=in[y];in[y]=cnt;e[cnt].f=0;
}
bool bfs()
{
memset(dep,0,sizeof(dep));
dep[s]=1;while(!que.empty()) que.pop();
que.push(s);
while(!que.empty())
{
int x=que.front();que.pop();
for(int i=in[x];i;i=e[i].lt)
{
int y=e[i].to;if(dep[y]||!e[i].f) continue;
dep[y]=dep[x]+1;que.push(y);
if(y==t) return true;
}
}
return false;
}
int dfs(int x,int flow)
{
if(x==t||!flow) return flow;
int cur=flow;
for(int i=in[x];i;i=e[i].lt)
{
int y=e[i].to;
if(dep[y]==dep[x]+1&&e[i].f)
{
int tmp=dfs(y,min(e[i].f,cur));
e[i].f-=tmp;e[i^1].f+=tmp;cur-=tmp;
if(!cur) return flow;
}
}
dep[x]=-1;return flow-cur;
}
void init()
{
cnt=1;
memset(in,0,sizeof(in));
}
int dinic()
{
int ans=0;
while(bfs()) ans+=dfs(s,inf);
//printf("%d\n",ans);
return ans;
}
int u[mxm],v[mxm],h[mxn],n,m,k;
bool check(int mid)
{
init();//printf("*%d ",mid);
for(int i=1;i<=k;i++) add(h[i],t,1);
for(int i=1;i<=m;i++) add(u[i],v[i],mid),add(v[i],u[i],mid);
if(dinic()>=k) return 1;
return 0;
}
int main()
{
int T,l,r,mid,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&k);
s=1;t=n+1;
for(int i=1;i<=k;i++) scanf("%d",&h[i]);
for(int i=1;i<=m;i++) scanf("%d%d",&u[i],&v[i]);
l=1;ans=r=n;
while(l<=r)
{
mid=l+r>>1;
if(check(mid)) r=mid-1,ans=mid;
else l=mid+1;
}
printf("%d\n",ans);
}
return 0;
}
SPOJ287 NETADMIN - Smart Network Administrator的更多相关文章
- SPOJ NETADMIN - Smart Network Administrator(二分)(网络流)
NETADMIN - Smart Network Administrator #max-flow The citizens of a small village are tired of being ...
- spoj 287 NETADMIN - Smart Network Administrator【二分+最大流】
在spoj上用题号找题就已经是手动二分了吧 把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流 ...
- Spoj-NETADMIN Smart Network Administrator
The citizens of a small village are tired of being the only inhabitants around without a connection ...
- [SPOJ 287] Smart Network Administrator 二分答案+网络流
The citizens of a small village are tired of being the only inhabitants around without a connection ...
- SPOJ287 Smart Network Administrator(最大流)
题目大概是说,一个村庄有n间房子,房子间有m条双向路相连.1号房子有网络,有k间房子要通过与1号房子相连联网,且一条路上不能有同样颜色的线缆,问最少要用几种颜色的线缆. 二分枚举颜色个数,建立容量网络 ...
- SPOJ 0287 Smart Network Administrator
题目大意:一座村庄有N户人家.只有第一家可以连上互联网,其他人家要想上网必须拉一根缆线通过若干条街道连到第一家.每一根完整的缆线只能有一种颜色.网管有一个要求,各条街道内不同人家的缆线必须不同色,且总 ...
- 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 ...
- internet connection sharing has been disabled by the network administrator
Start > Run > gpedit.msc Locate; Computer Configuration/Administrative Templates/Network/Netwo ...
- SPOJ NETADMIN_Smart Network Administrator
给一个图,某些点需要单独以某一种颜色的线连接到1点,问如何安排能够使得整个图颜色最多的一条路颜色最少. 显然,二分枚举然后加以颜色其实就是流量了,相当于对每条边限定一个当前二分的流量值,判断能否满流即 ...
随机推荐
- Python_013(面向对象概念)
一.面向对象 1.面向对象几个概念问题: a:类:具有相同属性和技能的一类事物.用代码表示就是,我类里面有一些静态变量和方法是大家共有的; b:对象:具体的类的表现.在代码中就是,调用类的方法或变量传 ...
- 解决Docker容器 iptables问题---docker: Error response from daemon: driver failed programming external connectivity on endpoint quizzical_thompson
一.问题现象 最近在研究Docker容器日志管理时,启动容器出现iptables相关报错,具体问题如下 运行容器 [root@node-11 ~]# docker run -d -p 24224:24 ...
- springboot编程之全局异常捕获
springboot编程之全局异常捕获 1.创建GlobalExceptionHandler.java,在类上注解@ControllerAdvice, 在方法上注解@ExceptionHandler( ...
- 关于web开发中路径的问题的总结
web开发中的一个困扰web开发新人的是路径问题: 1:项目的静态资源的根路径:http://localhost:8080/sqec-monitor 即是部署在web服务器中(比如tomcat)中项目 ...
- Linux学习篇(四)-Linux 文件管理命令详解
rootfs:根文件系统,Root FileSystem 的简称. Linux 文件命名规则 长度不超过255个字符. 不能使用/当文件名. 严格区分大小写. Linux 目录简介 / 根目录 /bo ...
- 数据可视化-D3js-展示古地理图和古地理坐标反算^_^gplates古地理坐标反算接口
在线演示 <!DOCTYPE html> <html> <head> <link type="image/png" rel="i ...
- 重写hashCode方法,导致内存泄漏
package com.nchu.learn.base.reflect; import org.junit.Test; import java.util.Collection; import java ...
- 思维导图初体验——openstack
RABBITMQ memcache keystone glance nova neutron horizon cinder ceph
- Node.js实战4:标准IO及console对像。
IO即输入输出. console用于Nodejs程序信息输出. Nodejs的IO操作,通过process.stdout.process.stdin来操作. 下面的例子,将简单展示这两个函数的用法.程 ...
- POJ-1611.TheSuspects.(并查集)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 55832 Accepted: 26501 De ...