Game on a Graph ZOJ - 4116

There are  people playing a game on a connected undirected simple graph with  () vertices (numbered from 0 to ) and  edges. These  people, numbered from 0 to , 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 will make the -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.

Input

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

The first line contains an integer  (), indicating the number of people.

The second line contains a string  of length  (). indicates that person number  belongs to the 1st group, and  indicates that person number  belongs to the 2nd group.

The third line contains two integers  and  (, ), indicating the number of vertices and edges of the initial graph.

The following  lines each contains two integers  and  (), indicating that there is an edge connecting vertex  and  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 , the sum of  and the sum of  in all test cases will not exceed .

 

Output

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).

Sample Input

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

Sample Output

2
1
2

图的去边问题,n个点,连线的条数最少有n-1条连线,找出拿n-1条的那个人,做下反转就行】

 

#include<iostream>
#include<cstdio>

using namespace std;
char s[100005];
int main()
{
    int t,n,m,a,b,x;
    cin>>t;
    while(t--){
        cin>>x;
        for(int i=0;i<x;i++){
            cin>>s[i];
        }
        cin>>n>>m;
        for(int i=0;i<m;i++){
            cin>>a>>b;
        }
        n--;
        m=m-n;
        m=m%x;
        if(s[m]=='1'){
            cout<<2<<endl;
        }else{
            cout<<1<<endl;
        }
    }
return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值