문제
Farmer John has recently been experimenting with cultivating different types of grass on his farm, realizing that different types of cows like different types of grass. However, he must be careful to ensure that different types of grass are planted sufficiently far away from each-other, in order to prevent them from being inextricably mixed.
FJ's farm consists of
In each field, FJ initially plants one of
After each update, FJ would like to know the length of the shortest path between two fields having different grass types. That is, among all pairs of fields having different grass types, he wants to know which two are closest. Ideally, this number is large, so he can prevent grass of one type from mixing with grass of another type. It is guaranteed that the farm will always have at least two fields with different grass types.
In 30 percent of the input cases, each field will be directly connected to at most 10 pathways.
Problem credits: Lewin Gan
입력
The first line of input contains four integers,
출력
For each update, print the length of the shortest path between two fields with different types of grass, after the update is applied.
예제
3 2 3 4
1 2 3
2 3 1
1 1 2
3 3
2 3
1 2
2 2
1
3
3
1