#P10777. BZOJ3706 反色刷

BZOJ3706 反色刷

Problem Description

Given an undirected graph with nn vertices and mm 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 xx-th edge (edges are numbered 0m10\sim m-1);
  • 2: query the minimum number of operations.

Input Format

The first line contains two integers n,mn, m, meaning the graph has nn vertices and mm edges.

The next mm lines each contain three integers u,v,cu, v, c, describing an undirected edge and its color, where 00 means white and 11 means black.

Then an integer qq follows, meaning there are qq operations. The next qq 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 1-1.

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: 1n,m,q10000001\leq n,m,q \leq 1000000, c<2c < 2, and there are no multiple edges or self-loops.

Translated by ChatGPT 5