codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

986A.md (2641B)


      1 Source: https://codeforces.com/problemset/problem/986/A
      2 
      3 A. Fair
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads.
     22 
     23 There are $k$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $s$ different types of goods. It costs $d(u,v)$ coins to bring goods from town $u$ to town $v$ where $d(u,v)$ is the length of the shortest path from $u$ to $v$. Length of a path is the number of roads in this path.
     24 
     25 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 $n$ towns.
     26 
     27 Input
     28 
     29 There are $4$ integers $n$, $m$, $k$, $s$ in the first line of input ($1 \le n \le 10^{5}$, $0 \le m \le 10^{5}$, $1 \le s \le k \le 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.
     30 
     31 In the next line there are $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_{i} \le k$), where $a_i$ is the type of goods produced in the $i$-th town. It is guaranteed that all integers between $1$ and $k$ occur at least once among integers $a_{i}$.
     32 
     33 In the next $m$ lines roads are described. Each road is described by two integers $u$ $v$ ($1 \le u, v \le n$, $u \ne 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.
     34 
     35 Output
     36 
     37 Print $n$ numbers, the $i$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $i$. Separate numbers with spaces.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 5 5 4 3  
     45 1 2 4 3 2  
     46 1 2  
     47 2 3  
     48 3 4  
     49 4 1  
     50 4 5
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 2 2 2 2 3
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 7 6 3 2  
     63 1 2 3 3 2 2 1  
     64 1 2  
     65 2 3  
     66 3 4  
     67 2 5  
     68 5 6  
     69 6 7
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 1 1 1 2 2 1 1
     76 ```
     77 
     78 Note
     79 
     80 Let's look at the first sample.
     81 
     82 To hold a fair in town $1$ you can bring goods from towns $1$ ($0$ coins), $2$ ($1$ coin) and $4$ ($1$ coin). Total numbers of coins is $2$.
     83 
     84 Town $2$: Goods from towns $2$ ($0$), $1$ ($1$), $3$ ($1$). Sum equals $2$.
     85 
     86 Town $3$: Goods from towns $3$ ($0$), $2$ ($1$), $4$ ($1$). Sum equals $2$.
     87 
     88 Town $4$: Goods from towns $4$ ($0$), $1$ ($1$), $5$ ($1$). Sum equals $2$.
     89 
     90 Town $5$: Goods from towns $5$ ($0$), $4$ ($1$), $3$ ($2$). Sum equals $3$.