## COCI '19 Contest 6 #2 Birmingham

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

It is well known that all horse races in Birmingham are fixed days in advance. It is a little less known that people who fix these races (and thereby know the winner) do that on a secret meeting and start spreading the information around the city the day after that meeting.

The first day after the meeting, all people that know the information about the winner start sharing that information with all people that live at most steps away from their house.

The second day after the meeting, all people that know the information about the winner start sharing that information with all people that live at most steps away from their house.

In general, -th day after the meeting, all people that know the information about the winner start sharing that information with all people that live at most steps away from their house.

We can represent Birmingham as a graph where vertices represent the houses and edges represent bidirectional roads which connect these houses. Houses are indexed with increasing integers from to and we say that a person can travel each road in a single step. It is possible to reach each house from each other house by traversing a sequence of roads.

Your task is to determine, for each house, on which day will the information about the race winner reach it.

#### Input

The first line contains four integers and , the number of houses in Birmingham, the number of roads in Birmingham, the number of people that were present on the secret meeting and the number from task description.

The next line contains integers where the -th integer represents the index of a house where the -th person from the secret meeting lives in.

The -th of the next lines contains integers and , which denote that the -th road connects houses with indices and .

#### Output

Output numbers where the -th number represents on which day after the meeting will the person living in house with index find out who will win the race. If the person living in that house was present on the secret meeting, output instead.

#### Scoring

In the test cases worth a total of points, it will hold and .

In the test cases worth an additional points, it will hold and .

#### Sample Input 1

6 8 1 1
6
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6

#### Sample Output 1

1 1 2 2 1 0

#### Sample Input 2

6 8 2 1
6 4
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6

#### Sample Output 2

1 1 1 0 1 0

#### Sample Input 3

6 8 1 2
6
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6

#### Sample Output 3

1 1 1 2 1 0

#### Explanation of Sample Output 3

The figure represents a graph from the third example. Since houses and are at most two steps away from house , people living in them will find out about the winner the day after the meeting. Person living in house will find out about the winner two days after the meeting.

• commented on Aug. 22, 2020, 1:40 p.m.

For Sample Input 1, How does house 4 receive the score on the second day?

Isn't it,

6 - > 1 - > 3 -> 4

House 4 receives the news on the third day?

What am I missing?

• commented on Aug. 22, 2020, 11:30 p.m.

In the first meeting, house 6 sends the score to house 1.

In the second meeting, house 1 sends the score to house 4.