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点,问如何安排能够使得整个图颜色最多的一条路颜色最少. 显然,二分枚举然后加以颜色其实就是流量了,相当于对每条边限定一个当前二分的流量值,判断能否满流即 ...
随机推荐
- 【LOMBOK】能引入 @Slf4j 注解,不能识别 log 的解决方法
问题: 在pom.xml中加入引入了lombok的依赖,可以引用@Slf4j注解不能识别log 如:注:上面一篇博客,已经说明lombok的安装了,但是用的时候还有点问题. 1).把lombok.ja ...
- Oracle dmp文件(表)导入与导出
dmp文件是作为oracle导入和导出表使用的文件格式dmp文件导出dmp文件导出用的比较多的一般是三种,他们分别是:1.导出整个数据库实例下的所有数据2.导出指定用户的所有表3.导出指定表. 打开命 ...
- Flask-SQLALchemy动态的filter_by和filter
1.filter_by filter_by用于查询简单的列名,不支持比较运算符. filters = {'name': 'fengyao', 'age': 26} User.query.filter_ ...
- Repository模式--采用EF Fluent API使用EntityTypeConfiguration分文件配置Model映射关系
EF中类EntityTypeConfiguration是一个很有用的类,在nopCommerence中就使用这个类来分文件分文件配置Model映射关系.今天我就来谈谈Repository模式在Enti ...
- python字符串常见操作
字符串常见操作 如有字符串mystr = 'hello world itcast and itcastcpp',以下是常见的操作 <1>find 检测 str 是否包含在 mystr中,如 ...
- Yaconf – 一个高性能的配置管理扩展
鸟哥出品:http://www.laruence.com/2015/06/12/3051.html 首先说说, 这个是干啥的. 我见过很多的项目中, 用PHP文件做配置的, 一个config目录下可能 ...
- List带索引的常用方法,以及集合的三种遍历
package cn.learn.collection.List; import com.sun.source.tree.NewArrayTree; import java.util.ArrayLis ...
- MySQL-第六篇DML语句
1.DML主要操作数据表里的数据,主要完成3个任务: 1>insert:插入数据.格式:insert into ... 2>delete:删除数据.格式:delete from ... 3 ...
- hive 分桶及抽样调查
1.分桶的概述 分区提供了一个隔离数据和优化查询的遍历方式.不是所有的数据集都可形成合力的分区 对于一张表或者分区,hive可以进一步组织成桶,也就是更为细粒度的数据范围 分区针对的是数据的存储路径( ...
- CodeChef Sereja and GCD
Sereja and GCD Problem code: SEAGCD Submit All Submissions All submissions for this problem ar ...