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的更多相关文章

  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. spoj 287 NETADMIN - Smart Network Administrator【二分+最大流】

    在spoj上用题号找题就已经是手动二分了吧 把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流 ...

  4. SPOJ 0287 Smart Network Administrator

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

  5. SPOJ287 NETADMIN - Smart Network Administrator

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

  6. SPOJ287 Smart Network Administrator(最大流)

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

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

  8. SPOJ NETADMIN_Smart Network Administrator

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

  9. internet connection sharing has been disabled by the network administrator

    Start > Run > gpedit.msc Locate; Computer Configuration/Administrative Templates/Network/Netwo ...

随机推荐

  1. Android学习总结(六)———— 发送自定义广播

    一.两种广播类型 2.1 标准广播 是一种完全异步执行的广播,在广播发出去之后,所有的广播接收器几乎都会在同一时刻接收到这条广播消息,因此它们之间没有任何先后顺序可言.这种广播的效率会比较高,但同时也 ...

  2. initWithNibName/awakeFromNib/initWithCoder

    转自: http://leeyin.iteye.com/blog/1040362 每个ios开发者对loadView和viewDidLoad肯定都很熟悉,虽然这两个函数使用上真的是非常简单,但是和类似 ...

  3. 树形dp——Tree2cycle

    一.问题描述(题目链接) 给你一棵树,删除或添加一条边的费用都是1,问使它变成一个环的最小费用. 二.解题思路 回溯法,然后回溯的时候的当前节点度数>2(如果是成环的话肯定就是2或者小于2)就把 ...

  4. flex常用属性

    <1>align-items: 垂直方向的对齐方式 align-items: stretch(拉伸,布满父容器) | center(垂直居中) | flex-start(上对齐) | fl ...

  5. python常用模块之requests

    一.requests 1.GET   url带参数请求 >>> payload = {'key1': 'value1', 'key2': 'value2'} >>> ...

  6. Codeforces Round #273 (Div. 2)-C. Table Decorations

    http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...

  7. Java数据结构面试题

    1.栈和队列的共同特点是(只允许在端点处插入和删除元素) 4.栈通常采用的两种存储结构是(线性存储结构和链表存储结构) 5.下列关于栈的叙述正确的是(D)      A.栈是非线性结构B.栈是一种树状 ...

  8. javase(13)_网络编程

    一.概述 1.网络编程的核心是IP.端口(表示应用程序).协议三大元素 2.网络编程的本质是进程间通信 3.网络编程的2个主要问题:1是定位主机,2是数据传输 二.网络通信的概念 1.网络通信协议 计 ...

  9. CentOS 6.6 安装nfs网络文件系统

    http://www.linuxidc.com/Linux/2015-06/119370.htm   ####搭建 http://blog.csdn.net/liumiaocn/article/det ...

  10. 洛谷 P1483 序列变换

    https://www.luogu.org/problemnew/show/P1483 数据范围不是太大. 一个数组记录给k,记录每个数加了多少. 对于查询每个数的大小,那么就枚举每个数的因子,加上这 ...