Spoj-NETADMIN Smart Network Administrator
The citizens of a small village are tired of being the only inhabitants around without a connection to the Internet. After nominating the future network administrator, his house was connected to the global network. All users that want to have access to the Internet must be connected directly to the admin's house by a single cable (every cable may run underground along streets only, from the admin's house to the user's house). Since the newly appointed administrator wants to have everything under control, he demands that cables of different colors should be used. Moreover, to make troubleshooting easier, he requires that no two cables of the same color go along one stretch of street.
Your goal is to find the minimum number of cable colors that must be used in order to connect every willing person to the Internet.
Input
t [the number of test cases, t<=500]
n m k [n <=500 the number of houses (the index of the admin's house is 1)]
[m the number of streets, k the number of houses to connect]
h1 h2 ... hk [a list of k houses wanting to be conected to the network, 2<=hi<=n]
[The next m lines contain pairs of house numbers describing street ends]
e11 e12
e21 e22
...
em1 em2
[next cases]
Output
For each test case print the minimal number of cable colors necessary to make all the required connections.
Example
Input:
2
5 5 4
2 3 4 5
1 2
1 3
2 3
2 4
3 5
8 8 3
4 5 7
1 2
1 8
8 7
1 3
3 6
3 2
2 4
2 5 Output:
2
1
Warning: large Input/Output data, be careful with certain languages
二分路径上出现过的最多种的颜色,然后网络流跑一跑看看能不能到达所有点
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,cnt,S,T;
int c[];
struct edge{
int to,next,v;
}e[];
struct ed{int x,y;}d[];
int head[];
int cur[];
inline void ins(int u,int v,int w)
{
e[++cnt].to=v;
e[cnt].next=head[u];
head[u]=cnt;
e[cnt].v=w;
}
inline void insert(int u,int v,int w)
{
ins(u,v,w);
ins(v,u,);
}
int h[];
int q[];
int ans;
inline bool bfs()
{
for (int i=;i<=T;i++)h[i]=-;
int t=,w=;
q[]=S;h[S]=;
while (t!=w)
{
int now=q[t++];
for(int i=head[now];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==-)
{
h[e[i].to]=h[now]+;
q[w++]=e[i].to;
}
}
return h[T]!=-;
}
inline int dfs(int x,int f)
{
if (x==T||!f)return f;
int w,used=;
for (int i=head[x];i;i=e[i].next)
if (e[i].v&&h[e[i].to]==h[x]+)
{
w=dfs(e[i].to,min(e[i].v,f-used));
e[i].v-=w;
e[i^].v+=w;
used+=w;
if (f==used)return f;
}
if (!used)h[x]=-;
return used;
}
inline void rebuild(int mid)
{
for (int i=;i<=T;i++)head[i]=;
S=;T=n+;cnt=;
for (int i=;i<=k;i++)insert(c[i],T,);
for (int i=;i<=m;i++)
{
insert(d[i].x,d[i].y,mid);
insert(d[i].y,d[i].x,mid);
}
}
inline bool jud(int mid)
{
rebuild(mid);
ans=;while (bfs())ans+=dfs(S,inf);
return ans==k;
}
inline void work()
{
n=read();m=read();k=read();
for (int i=;i<=k;i++)c[i]=read();
for (int i=;i<=m;i++)
{
d[i].x=read();
d[i].y=read();
}
int l=,r=k,col=k;
while (l<=r)
{
int mid=(l+r)>>;
if (jud(mid))col=mid,r=mid-;
else l=mid+;
}
printf("%d\n",col);
}
int main()
{
int T=read();
while (T--)work();
}
Spoj NETADMIN
Spoj-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] Smart Network Administrator 二分答案+网络流
The citizens of a small village are tired of being the only inhabitants around without a connection ...
- spoj 287 NETADMIN - Smart Network Administrator【二分+最大流】
在spoj上用题号找题就已经是手动二分了吧 把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流 ...
- SPOJ 0287 Smart Network Administrator
题目大意:一座村庄有N户人家.只有第一家可以连上互联网,其他人家要想上网必须拉一根缆线通过若干条街道连到第一家.每一根完整的缆线只能有一种颜色.网管有一个要求,各条街道内不同人家的缆线必须不同色,且总 ...
- SPOJ287 NETADMIN - Smart Network Administrator
传送门[洛谷] 常见套路? 关键点连新建汇点 流量1 源点1 原图中的边 二分流量. 二分+判满流 做完了. 附代码. #include<cstdio> #include<cstri ...
- SPOJ287 Smart Network Administrator(最大流)
题目大概是说,一个村庄有n间房子,房子间有m条双向路相连.1号房子有网络,有k间房子要通过与1号房子相连联网,且一条路上不能有同样颜色的线缆,问最少要用几种颜色的线缆. 二分枚举颜色个数,建立容量网络 ...
- 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 NETADMIN_Smart Network Administrator
给一个图,某些点需要单独以某一种颜色的线连接到1点,问如何安排能够使得整个图颜色最多的一条路颜色最少. 显然,二分枚举然后加以颜色其实就是流量了,相当于对每条边限定一个当前二分的流量值,判断能否满流即 ...
- internet connection sharing has been disabled by the network administrator
Start > Run > gpedit.msc Locate; Computer Configuration/Administrative Templates/Network/Netwo ...
随机推荐
- 添加/删除 windows下Git右键菜单
从网上搜索了些方法,总结一下 不显示右键菜单: 方法1: 安装的时候选择不添加右键菜单. 方法2(绝对有效): 运行CMD Windows 64 输入命令(地址为git安装地址) cd "C ...
- 在ABAP里模拟实现Java Spring的依赖注入
Dependency Injection- 依赖注入,在Java Spring框架中有着广泛地应用.通过依赖注入,我们不必在应用代码里繁琐地初始化依赖的资源,非常方便. 那么ABAP能否从语言层面上也 ...
- activeandroid复制本地数据库问题总结
activeandroid no such table 解决activeandroid no such table failed to read row 0 column 1 from a curso ...
- 46.Maximum Product Subarray(最大乘积子数组)
Level: Medium 题目描述: Given an integer array nums, find the contiguous subarray within an array (con ...
- Log4J的配置与使用详解
一.简介 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务器.NT的事件记录器.UNIX Syslog守护 ...
- glassfish配置中数据库密码加密方法
glassfish配置中数据库密码加密方法 Glassfish中的数据库连接池需要使用密文保存数据库密码.如果不是,则可按如下方法可配置 通过Glassfish中的Alias实现,配置方法如下: 1. ...
- Pomodoro APP
2015.5.23 UITableView 的数据源刷新问题 本次发过来的版本五,实现了活动清单列表(AllEventsTableViewController).活动详情(AllEventsViewC ...
- linux配置nodeJs环境教程
来自阿里云:https://help.aliyun.com/document_detail/50775.html
- Educational Codeforces Round 40千名记
人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还 ...
- Linux基础学习-使用DHCP动态管理主机地址
动态主机配置协议 部署dhcpd服务程序 参数 作用 ddns-update-style none; 设置DNS服务不自动进行动态更新 ignore client-updates; 忽略客户端更新DN ...