Farmer John has recently been experimenting with cultivating different types of grass on his farm, r
ealizing 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 Nfields (1≤N≤200,000), where M pa
irs of fields are connected by bi-directional pathways (1≤M≤200,000). Using these pathways, it is
possible to walk from any field to any other field. Each pathway has an integer length in the range
1…1,000,000. Any pair of fields will be linked by at most one direct pathway.In each field, FJ init
ially plants one of Ktypes of grass (1≤K≤N). Over time, however, he might decide to switch the gra
ss in some field to a different type. He calls this an "update" operation. He might perform several
updates over the course of time, which are all cumulative in nature.After each update, FJ would like
to know the length of the shortest path between two fields having different grass types. That is, a
mong all pairs of fields having different grass types, he wants to know which two are closest. Ideal
ly, 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.
给定一张带权无向图,每个点有一个颜色,每次改变一个点的颜色,要求你在操作后输出这个图中最近异色点对之
间的距离最近异色点对定义为:一对点颜色不同,且距离最小