#P3665. [USACO17OPEN] Switch Grass P
[USACO17OPEN] Switch Grass P
题目描述
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 fields (), where pairs of fields are connected by bi-directional pathways (). Using these pathways, it is possible to walk from any field to any other field. Each pathway has an integer length in the range . Any pair of fields will be linked by at most one direct pathway.
In each field, FJ initially plants one of types of grass (). Over time, however, he might decide to switch the grass in some field to a different type. He calls this an "update" peration. 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, 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.
输入格式
The first line of input contains four integers, , , , and , where is the number of updates ().
The next lines describe the paths; each one contains three integers , , and , indicating a path from field to field (both integers in the range ) of length .
The next line indicates the initial type of grass growing in each field ( integers in the range ).
Finally, the last lines each describe an update, specified by two integers and , where the grass in field is to be updated to type .
输出格式
For each update, print the length of the shortest path between two fields with different types of grass, after the update is applied.
题目大意
农夫约翰最近一直在在他的农场试种各种类型的草,他发现不同类型的牛,喜欢不同类型的草。然而,他必须注意,在种草时,不同类型的草,要保持足够远的距离,以防止它们混合。他的农场由总共 块田地组成,其中有 对田地中用小路连接。通过这些小路,这些田地联通。每条路的长度在 范围内。没有重边。
对于每个田地,草的品种是 种草 中的一种。然而,随着时间的推移,他可能决定在某些田地将草转变为不同品种,称之为“更新”。他可能会在一段时间内执行多次更新,这些更新都是累积的。
在每次更新之后,他想知道具有不同草品种的两个田地之间的最短路径的长度。也就是说,在具有不同草品种的所有田地中,他想知道哪两个是最接近的。保证农场将总是具有至少两个具有不同草品种的田地。
输入格式
第一行输入四个整数 , 代表“更新”的次数。
接下来 行,输入三个整数 ,代表一条从 到 的长度为 的双向边。
下一行输入 个数,每个数代表这块田地一开始种的哪种草(在 )范围内。
最后输入 行,每行两个整数 表示第 块田地的草被换成了第 品种。
输出格式
总共有 行,每行一个整数。
每个更新后,输出不同种类草之间的最短距离。
数据范围
。
对于所有边,有 。
对于 30% 的数据,保证每个田地衍生出来的道路条数 。
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
提示
感谢 @∑∵∴∷ 的翻译。
简洁翻译 by cc123321 :
给定一张带权无向图,每个点有一个颜色,每次改变一个点的颜色,要求你在操作后输出这个图中最近异色点对之间的距离。最近异色点对定义为:一对点颜色不同,且距离最小。