#P10777. BZOJ3706 反色刷
BZOJ3706 反色刷
Problem Description
Given an undirected graph with vertices and edges, each edge is colored either black or white. You may perform several cycle color-inversion operations. In each operation, you start from any vertex, traverse edges, and for every edge you pass through, you invert its color. Finally, you return to the starting vertex. Determine whether it is possible, after some operations, to make all edges in the graph white.
For some reason, edge colors can change. That is, you need to support the following two operations:
1 x: invert the color of the -th edge (edges are numbered );2: query the minimum number of operations.
Input Format
The first line contains two integers , meaning the graph has vertices and edges.
The next lines each contain three integers , describing an undirected edge and its color, where means white and means black.
Then an integer follows, meaning there are operations. The next lines contain the operations, as described above.
Output Format
For each query, output one integer per line, representing the minimum number of color-inversion operations needed. If there is no valid solution, output .
6 6
1 2 1
2 3 1
1 3 1
4 5 1
5 6 1
4 6 1
14
2
1 0
2
1 1
1 2
2
1 3
1 4
1 5
2
1 3
1 4
1 5
2
2
-1
1
0
1
Hint
Constraints: , , and there are no multiple edges or self-loops.
Translated by ChatGPT 5