#P10875. [COTS 2022] 游戏 M

[COTS 2022] 游戏 M

Background

Translated from Izborne Pripreme 2022 (Croatian IOI/CEOI Team Selection) D2T2。3s,0.5G\texttt{3s,0.5G}

Problem Description

There is an undirected graph with NN nodes. We add MM edges to the graph one by one.

There are QQ queries. Each query gives u,vu, v and asks: what is the minimum number of first edges that must be added so that there is no bridge on the connection between uu and vv (in other words, removing any single edge will not affect the connectivity between uu and vv)? In particular, if uu and vv are always disconnected, or there is always a bridge, output 1-1.

Input Format

The first line contains two integers N,MN, M, as described in the statement.

The next MM lines: the ii-th line contains two integers si,tis_i, t_i, meaning the ii-th edge is (si,ti)(s_i, t_i).

The (M+2)(M+2)-th line contains an integer QQ, as described in the statement.

The next QQ lines: each line contains two integers u,vu, v, describing a query.

Output Format

Output QQ lines. Each line contains one integer, the answer to the query.

3 3
1 2
2 3
3 1
1
1 2
3
3 4
1 2
1 2
2 3
2 3
3
1 2
2 3
3 1
2
4
4
6 7
1 2
2 3
3 4
2 5
3 5
4 5
1 3
5
1 3
2 3
4 5
1 4
2 6
7
5
6
7
-1

Hint

For 100%100\% of the testdata, it is guaranteed that:

  • 2N3×1052\le N \le 3\times 10^5, 0M3×1050\le M\le 3\times 10^5, 1Q3×1051\le Q\le 3\times 10^5
  • sitis_i\neq t_i, uvu\neq v
  • 1u,v,si,tiN1\le u,v,s_i,t_i\le N
Subtask ID Score Constraints
11 1010 Q=1Q=1
22 2020 2M2\mid M(s2i1,t2i1)=(s2i,t2i)(s_{2i-1},t_{2i-1})=(s_{2i},t_{2i})
33 3030 N,M5000N,M\le 5\, 000
44 4040 No additional constraints.

Translated by ChatGPT 5