#P14045. [SDCPC 2019] Game on a Graph

[SDCPC 2019] Game on a Graph

题目描述

There are kk people playing a game on a connected undirected simple graph with nn (n2n \ge 2) vertices (numbered from 0 to (n1)(n-1)) and mm edges. These kk people, numbered from 0 to (k1)(k-1), are divided into two groups and the game goes as follows:

  • They take turns to make the move. That is to say, person number 0 will make the 1st move, person number 1 will make the 2nd move, ..., person number (imodk)(i \bmod k) will make the (i+1)(i+1)-th move.
  • During a move, the current player MUST select an edge from the current graph and remove it. If the graph is no longer connected after removing the edge, the group this person belongs to loses the game (and of course their opponents win), and the game ends immediately.

Given the initial graph when the game starts, if all people use the best strategy to win the game for their groups, which group will win the game?

Recall that a simple graph is a graph with no self loops or multiple edges.

输入格式

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains an integer kk (2k1052 \le k \le 10^5), indicating the number of people.

The second line contains a string s0s1sk1s_0s_1\dots s_{k-1} of length kk (si{‘1’,‘2’}s_i \in \{\text{`1'}, \text{`2'}\}). si=‘1’s_i = \text{`1'} indicates that person number ii belongs to the 1st group, and si=‘2’s_i = \text{`2'} indicates that person number ii belongs to the 2nd group.

The third line contains two integers nn and mm (2n1052 \le n \le 10^5, n1m105n-1 \le m \le 10^5), indicating the number of vertices and edges of the initial graph.

The following mm lines each contains two integers uiu_i and viv_i (0ui,vi<n0 \le u_i, v_i < n), indicating that there is an edge connecting vertex uiu_i and viv_i in the initial graph.

It's guaranteed that:

  • The initial graph is a connected undirected simple graph.
  • There exist two people who belong to different groups.
  • The sum of kk, the sum of nn and the sum of mm in all test cases will not exceed 10610^6.

输出格式

For each test case output one line containing one integer. If the 1st group wins, output 1 (without quotes); If the 2nd group wins, output 2 (without quotes).

3
5
11212
4 6
0 1
0 2
0 3
1 2
1 3
2 3
5
11121
5 7
0 2
1 3
2 4
0 3
1 2
3 2
4 1
3
121
4 3
0 1
0 2
1 3
2
1
2