CF1413F.Roads and Ramen
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the Land of Fire there are n villages and n−1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every morning workers choose a single road and flip its type (so it becomes a stone road if it was a sand road and vice versa). Also everyone here loves ramen, that's why every morning a ramen pavilion is set in the middle of every stone road, and at the end of each day all the pavilions are removed.
For each of the following m days, after another road is flipped, Naruto and Jiraiya choose a simple path — that is, a route which starts in a village and ends in a (possibly, the same) village, and doesn't contain any road twice. Since Naruto and Jiraiya also love ramen very much, they buy a single cup of ramen on each stone road and one of them eats it. Since they don't want to offend each other, they only choose routes where they can eat equal number of ramen cups. Since they both like traveling, they choose any longest possible path. After every renovation find the maximal possible length of a path (that is, the number of roads in it) they can follow.
在火之国,有 n 个村庄和 n−1 条双向道路,且任意两个村庄之间都存在一条仅由道路构成的路径。道路仅有两种类型:石质道路与沙质道路。由于火之国持续进行道路翻新,每天清晨,工人们会选定恰好一条道路,并将其类型翻转(即若原为沙质道路,则变为石质道路;反之亦然)。此外,当地人人热爱拉面,因此每天清晨,每条石质道路的正中央都会设立一座拉面亭;而每天结束时,所有拉面亭均被撤除。
在接下来的 m 天中,每一天均先执行一次道路类型翻转操作;随后,鸣人与自来也选择一条简单路径——即起点与终点均为村庄(二者可以相同),且路径中不重复经过任何道路的路线。由于鸣人与自来也也非常喜爱拉面,他们在路径上每经过一条石质道路,就购买并食用一杯拉面(两人共用该杯,仅一人食用)。为避免彼此冒犯,他们只选择那些能使两人所食拉面杯数相等的路径(即路径中石质道路的数量为偶数,从而可均分)。又因二人都热爱旅行,他们总是选择尽可能长的满足条件的路径。请对每次翻新操作之后,求出他们所能选择的路径的最大可能长度(即路径所含道路的条数)。
输入格式
The first line contains the only positive integer n (2≤n≤500000) standing for the number of villages in the Land of Fire.
Each of the following (n−1) lines contains a description of another road, represented as three positive integers u, v and t (1≤u,v≤n, t∈0,1). The first two numbers denote the villages connected by the road, and the third denotes the initial type of the road: 0 for the sand one and 1 for the stone one. Roads are numbered from 1 to (n−1) in the order from the input.
The following line contains a positive integer m (1≤m≤500000) standing for the number of days Naruto and Jiraiya travel for.
Each of the following m lines contains the single integer id (1≤id≤n−1) standing for the index of the road whose type is flipped on the morning of corresponding day.
It is guaranteed that there is a road path between any pair of villages.
第一行包含唯一的一个正整数 n(2≤n≤500000),表示火之国中村庄的数量。
接下来的 (n−1) 行,每行描述一条道路,由三个正整数 u、v 和 t(1≤u,v≤n,t∈{0,1})组成。前两个数表示该道路所连接的两个村庄,第三个数表示该道路的初始类型:0 表示沙土路,1 表示石板路。道路按输入顺序编号为 1 至 (n−1)。
接下来的一行包含一个正整数 m(1≤m≤500000),表示鸣人和自来也旅行的天数。
接下来的 m 行,每行包含一个整数 id(1≤id≤n−1),表示在对应天的早晨,编号为 id 的道路类型将被翻转(即 0 变为 1,1 变为 0)。
保证任意两个村庄之间均存在道路路径。
输出格式
Output m lines. In the i-th of them print the only integer denoting the maximal possible length of any valid path on the i-th day.
输出 m 行。在第 i 行中,输出一个整数,表示第 i 天任意有效路径的最大可能长度。
输入输出样例
输入#1
5 1 2 0 1 3 0 3 5 0 3 4 0 5 3 4 1 3 4
输出#1
3 2 3 3 2
说明/提示
After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.
After the renovation of the 4-th road one of the longest paths consists of the roads 1 and 2.
After the renovation of the 1-st road one of the longest paths consists of the roads 1, 2 and 3.
After the renovation of the 3-rd road the longest path consists of the roads 1, 2 and 4.
After the renovation of the 4-rd road one of the longest paths consists of the roads 2 and 4.
第3条道路翻新后,最长路径由道路1、2和4组成。
第4条道路翻新后,一条最长路径由道路1和2组成。
第1条道路翻新后,一条最长路径由道路1、2和3组成。
第3条道路翻新后,最长路径由道路1、2和4组成。
第4条道路翻新后,一条最长路径由道路2和4组成。
输入解题思路,AI测评打分。不知道怎么写?