Some company is going to hold a fair in Byteland. There are nn towns in Byteland and mm two-way roads between towns. Of course, you can reach any town from any other town using roads.

There are kk types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least ss different types of goods. It costs d(u,v)d(u,v) coins to bring goods from town uu to town vv where d(u,v)d(u,v) is the length of the shortest path from uu to vv . Length of a path is the number of roads in this path.

The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of nn towns.

Input

There are 44 integers nn , mm , kk , ss in the first line of input (1≤n≤1051≤n≤105 , 0≤m≤1050≤m≤105 , 1≤s≤k≤min(n,100)1≤s≤k≤min(n,100) ) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair.

In the next line there are nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤k1≤ai≤k ), where aiai is the type of goods produced in the ii -th town. It is guaranteed that all integers between 11 and kk occur at least once among integers aiai .

In the next mm lines roads are described. Each road is described by two integers uu vv (1≤u,v≤n1≤u,v≤n , u≠vu≠v ) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.

Output

Print nn numbers, the ii -th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town ii . Separate numbers with spaces.

Examples

Input
5 5 4 3
1 2 4 3 2
1 2
2 3
3 4
4 1
4 5
Output
2 2 2 2 3 
Input
7 6 3 2
1 2 3 3 2 2 1
1 2
2 3
3 4
2 5
5 6
6 7
Output
1 1 1 2 2 1 1 

Note

Let's look at the first sample.

To hold a fair in town 11 you can bring goods from towns 11 (00 coins), 22 (11 coin) and 44 (11 coin). Total numbers of coins is 22 .

Town 22 : Goods from towns 22 (00 ), 11 (11 ), 33 (11 ). Sum equals 22 .

Town 33 : Goods from towns 33 (00 ), 22 (11 ), 44 (11 ). Sum equals 22 .

Town 44 : Goods from towns 44 (00 ), 11 (11 ), 55 (11 ). Sum equals 22 .

Town 55 : Goods from towns 55 (00 ), 44 (11 ), 33 (22 ). Sum equals 33 .

Fair
思路:
大体思路就是先储存路线和生产地,再就是用bfs找到每一个产品生产地到其他城市最短距离,最后sort进行排序,
求出前s个得和即可。
bfs
第一次进入while,目的是找到生产x产品所有的生产地,第二次,是对每一个生产地进行往后延生,就是找到与这个地方相邻得
地方,距离再加1.
 
这个最短路bfs的思路要好好整理,以后还可以用到的
就是用bfs,对它附近的城市距离加+1,这个vector的处理要注意学习!!!!!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=1e5+1000;
vector<int>exa[maxn];
int mov[maxn][110],n; void bfs(int x)
{
queue<int>que;
int i,u,v;
que.push(x+n);
while(!que.empty())
{
u=que.front();que.pop();
for(i=0;i<exa[u].size();i++)
{
v=exa[u][i];
if(mov[v][x]==0)
{
mov[v][x]=mov[u][x]+1;
que.push(v);
}
}
}
} int main()
{
int m,k,s,a,u,v;
scanf("%d %d %d %d",&n,&m,&k,&s);
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
exa[a+n].push_back(i);
}
for(int i=1;i<=m;i++)
{
scanf("%d%d",&u,&v);
exa[u].push_back(v);
exa[v].push_back(u);
}
for(int i=1;i<=k;i++) bfs(i);
for(int i=1;i<=n;i++) sort(mov[i]+1,mov[i]+k+1);
for(int i=1;i<=n;i++)
{
int cnt=0;
for(int j=1;j<=s;j++) cnt+=mov[i][j]-1;
i==n?printf("%d\n",cnt):printf("%d ",cnt);
}
return 0;
}

  

 

寒假特训——I - Fair的更多相关文章

  1. Android寒假实训云笔记总结——欢迎页

    欢迎页使用的是viewpager,需要适配器. 注意点: 1.判断是否是第一次进入这个app. 2.欢迎页小圆点的逻辑. 实现原理: 首先在activity_welcome放入viewpager和固定 ...

  2. 寒假特训——搜索——H - Nephren gives a riddle

    What are you doing at the end of the world? Are you busy? Will you save us? Nephren is playing a gam ...

  3. Gym 101889:2017Latin American Regional Programming Contest(寒假自训第14场)

    昨天00.35的CF,4点才上床,今天打的昏沉沉的,WA了无数发. 题目还是满漂亮的. 尚有几题待补. C .Complete Naebbirac's sequence 题意:给定N个数,他们在1到K ...

  4. Gym 101655:2013Pacific Northwest Regional Contest(寒假自训第13场)

    A .Assignments 题意:给定距离D,以及N个飞机的速度Vi,单位时间耗油量Fi,总油量Ci.问有多少飞机可以到达目的地. 思路:即问多少飞机满足(Ci/Fi)*Vi>=D  ---- ...

  5. Gym101986: Asia Tsukuba Regional Contest(寒假自训第12场)

    A .Secret of Chocolate Poles 题意:有黑白两种木块,黑色有1,K两种长度: 白色只有1一种长度,问满足黑白黑...白黑形式,长度为L的组合种类. 思路:直接DP即可. #i ...

  6. Gym.102006:Syrian Collegiate Programming Contest(寒假自训第11场)

    学习了“叙利亚”这个单词:比较温和的一场:几何的板子eps太小了,坑了几发. A .Hello SCPC 2018! 题意:给定一个排列,问它是否满足,前面4个是有序的,而且前面4个比后面的都小. 思 ...

  7. Gym.101955: Asia Shenyang Regional Contest(寒假自训第10场)

    C.Insertion Sort 题意:Q次询问,每次给出N,M,Mod,问你有多少种排列,满足前面M个数字排序之后整个序列的LIS>=N-1. 思路:我们把数字看成[1,M],[N-M+1,N ...

  8. Gym102040 .Asia Dhaka Regional Contest(寒假自训第9场)

    B .Counting Inversion 题意:给定L,R,求这个区间的逆序对数之和.(L,R<1e15) 思路:一看这个范围就知道是数位DP. 只是维护的东西稍微多一点,需要记录后面的各种数 ...

  9. Gym-101673 :East Central North America Regional Contest (ECNA 2017)(寒假自训第8场)

    A .Abstract Art 题意:求多个多边形的面积并. 思路:模板题. #include<bits/stdc++.h> using namespace std; typedef lo ...

随机推荐

  1. 依然是关于我空间那篇申请的日志《JavaScript axError:Unexpected token ILLEGAL 很简单的代码……》

    接下来要讲的日志现在的标题已经更改为<很简单的代码,但是无法--> 这篇日志地址:http://www.cnblogs.com/herbertchina/p/4475092.html 经过 ...

  2. c#调用腾讯云API的实例

    //获取时间戳 .net framework /* DateTime dt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1 ...

  3. mysql中general_log查询日志

    作为mysql的通用查询日志,记录增删改查操作的,都有日志文件记录的. 经上网查资料,得知,通用查询日志--可以关闭 show global variables like '%general%'; 同 ...

  4. (5)Microsoft office Word 2013版本操作入门_标尺

    1.标尺 :左缩进,右缩进,悬挂缩进,首行缩进,阴影部分 可以左右拖拽调整边缘. 1.1  左缩进:默认缩进所在的段落,要缩进多段则需要多段落选中, 后拖动左缩进. 1.2 首行缩进缩进或者突出所选的 ...

  5. virtualbox中设置u盘启动

    1.在磁盘管理中查看u盘的磁盘号X 2.管理员运行cmd,进入virtualbox目录 3.运行命令: VBoxManage internalcommands createrawvmdk -filen ...

  6. VSCode Snippet 小试牛刀

    这几天因为一个需求,要不断重复一个用特定代码段去包围不同代码的需求. 这个要不断移动鼠标以及重复敲打相同代码的体力活,实在让我老眼昏花,体内的懒人之力迫使我想一个快捷的方法来代替之. 之前就知道Sni ...

  7. js canvas 转动时钟实例

    源码:https://pan.baidu.com/s/1R12MwZYs0OJw3OWKsc8WNw 样本:http://js.zhuamimi.cn/shizhong/ 我的百度经验:https:/ ...

  8. 小tips:JS严格模式(use strict)下不能使用arguments.callee的替代方案

    在函数内部,有两个特殊的对象:arguments 和 this.其中, arguments 的主要用途是保存函数参数, 但这个对象还有一个名叫 callee 的属性,该属性是一个指针,指向拥有这个 a ...

  9. SSH密钥对登录的原理和实践

    1.ssh密钥对登录的基本思路是:要登录谁,就把公钥放到谁身上,就可以授权登录谁. 2.本地登录设备称为ssh客户端,被登录的设备称为ssh服务器. 3.原理图描述如下: 4.SSH的公钥分为open ...

  10. ReactNative编写规范

    <一>  React 代码规范 文件与组件命名 扩展名: 使用.js作为js文件的扩展名.如果同一个文件夹下有同名而不同作用的js文件,则通过中缀(小写)进一步区分,例如:HomePage ...