Did you know that cactus graphs once enjoyed a glorious era in Taiwan's competitive programming scene, especially in 2022?
Looking back, the 2021 NTU ICPC Team Preliminary Contest featured a problem that required answering multiple shortest-path distance queries on a cactus graph$$$^{\text{∗}}$$$, marking the beginning of the Great Cactus Era. In 2022, cactus graphs reached the height of their glory. First, IOICamp featured a problem about answering maximum contiguous path-sum queries between pairs of vertices in a cactus graph$$$^{\text{†}}$$$. Later, YTP featured a problem asking for the maximum-weight independent set of a cactus graph$$$^{\text{‡}}$$$. Incidentally, this problem was so difficult that even the first-place team solved every problem except this one! Finally, that year's NTU ICPC Team Preliminary Contest featured yet another problem combining cactus graphs with linear basis$$$^{\text{§}}$$$.
Unfortunately, since 2023, cactus graphs have almost completely disappeared from programming contests in Taiwan. What a shame! Now, you are given a simple, connected, undirected cactus graph with $$$n$$$ vertices and $$$m$$$ edges. Each edge has a positive integer weight. There is a set of vertices $$$S$$$ which is initially empty. Please process $$$q$$$ operations. Each operation specifies a vertex $$$v$$$ and toggles whether $$$v$$$ belongs to $$$S$$$. That is,
After each operation, output the maximum shortest-path distance between any two vertices in $$$S$$$. That is, let $$$d(u,v)$$$ be the length of the shortest path between vertices $$$u$$$ and $$$v$$$. You should output
$$$$$$ \max_{u,v\in S} d(u,v) $$$$$$
after each operation. Note that if $$$|S| \leq 1$$$, the answer is defined to be $$$0$$$.
To make the problem more interesting, all operations are encoded and must be processed online. See the input format for details.
Note that an undirected graph is called a cactus graph if every edge belongs to at most one simple cycle.
$$$^{\text{∗}}$$$https://ntuj.csie.org/problems/3282
$$$^{\text{†}}$$$https://oj.ntucpc.org/problems/181
$$$^{\text{‡}}$$$https://oj.ntucpc.org/problems/329
$$$^{\text{§}}$$$https://ntuj.csie.org/problems/3463
The first line contains three integers $$$n$$$, $$$m$$$, and $$$q$$$, denoting the number of vertices, the number of edges, and the number of operations, respectively.
Each of the next $$$m$$$ lines contains three positive integers $$$u_i$$$, $$$v_i$$$, and $$$w_i$$$, indicating that there is an undirected edge of weight $$$w_i$$$ between vertices $$$u_i$$$ and $$$v_i$$$.
Each of the next $$$q$$$ lines contains an integer $$$x_i$$$, representing the encoded information for the $$$i$$$-th operation.
Let $$$\operatorname{ans}_i$$$ be the answer after the $$$i$$$-th operation, and let $$$y_i$$$ be the vertex that is actually toggled by the $$$i$$$-th operation. Then
$$$$$$ y_i=\operatorname{ans}_{i-1}\oplus x_i, $$$$$$
where $$$\oplus$$$ denotes the bitwise XOR operation. Also, we define $$$\operatorname{ans}_0=0$$$.
Output $$$q$$$ lines. The $$$i$$$-th line should contain one integer $$$\operatorname{ans}_i$$$, the maximum shortest-path distance between any two vertices in $$$S$$$ after the $$$i$$$-th operation.
15 19 2010 13 411 1 214 12 59 5 58 5 914 8 1015 11 513 3 36 3 613 6 1013 7 11 15 54 15 87 10 814 2 614 10 512 8 14 3 72 10 7614312736443742471730441813041683130
0 18 18 38 38 38 38 38 23 17 32 29 14 11 34 11 7 29 27 42
8 8 102 1 52 7 38 5 45 4 16 4 53 2 41 6 54 2 22826134915104
0 7 7 12 7 11 11 11 12 9