Game on a Graph

Time Limit: 1 Second Memory Limit: 65536 KB

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条边构成了联通图。有人说是博弈论,反正我没看出来

一开始以为是无向图,打算往后放放,突然队友告诉我读错题了,尴尬!?

#include <bits/stdc++.h>
using namespace std;
char ob[100005];
int main()
{
int t,n, x,y,z;
cin>>t;
while(t--)
{
cin>>n;
for(int i=0;i<n;i++) cin>>ob[i];
cin>>x>>y;
for(int i=0;i<y;i++) cin>>z>>z;
y=(y-x+1)%n;
if(ob[y]=='1')cout<<2<<endl;
else cout<<1<<endl;
}
}

ACM-ICPC 2019 山东省省赛D Game on a Graph的更多相关文章

  1. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  2. ACM-ICPC 2019 山东省省赛总结

    五题手快拿银,不然拿铜,甚至不拿,从结果上来看拿了铜牌对第一年的我们来说算好的,也不算太好. 从拿奖后的第一天,我想写这篇博客,但是我忍了下来,那时候被喜悦冲昏了头脑,当 冷静下来,我开始打算写这篇博 ...

  3. 2014 ACM/ICPC 鞍山赛区现场赛 D&amp;I 解题报告

    鞍山现场赛结束了呢-- 我们出的是D+E+I三道题-- 吾辈AC掉的是D和I两道,趁着还记得.先在这里写一写我写的两道水题D&I的解题报告吧^_^. D题的意思呢是说星云内有一堆排成一条直线的 ...

  4. Substrings 第37届ACM/ICPC 杭州赛区现场赛C题(hdu 4455)

    http://acm.hdu.edu.cn/showproblem.php?pid=4455 https://icpcarchive.ecs.baylor.edu/index.php?option=c ...

  5. 2014 ACM/ICPC 鞍山赛区网络赛(清华命题)

    为迎接10月17号清华命题的鞍山现场赛 杭电上的题目 Biconnected(hdu4997)     状态压缩DP Rotate(hdu4998)    相对任一点的旋转 Overt(hdu4999 ...

  6. hdu 4431 第37届ACM/ICPC 天津赛区现场赛A题 枚举

    题意:就是给了13张牌.问增加哪些牌可以胡牌.m是数字,s是条,p是筒,c是数字 胡牌有以下几种情况: 1.一个对子 +  4组 3个相同的牌或者顺子.  只有m.s.p是可以构成顺子的.东西南北这样 ...

  7. hdu 4438 第37届ACM/ICPC 天津赛区现场赛H题

    题意:Alice和Bob两个人去打猎,有两种(只)猎物老虎和狼: 杀死老虎得分x,狼得分y: 如果两个人都选择同样的猎物,则Alice得分的概率是p,则Bob得分的概率是(1-p): 但是Alice事 ...

  8. zoj 3659 第37届ACM/ICPC 长春赛区现场赛E题 (并查集)

    题意:给出一棵树,找出一个点,求出所有点到这个点的权值和最大,权值为路径上所有边权的最小值. 用神奇的并查集,把路按照权值从大到小排序,然后用类似Kruskal的方法不断的加入边. 对于要加入的一条路 ...

  9. 2017 ACM/ICPC 南宁区 网络赛 Overlapping Rectangles

    2017-09-24 20:11:21 writer:pprp 找到的大神的代码,直接过了 采用了扫描线+线段树的算法,先码了,作为模板也不错啊 题目链接:https://nanti.jisuanke ...

随机推荐

  1. Windows 手动安装 Apache24 web服务器

    文章更新于:2020-02-18 按照惯例,需要的文件附上链接放在文首 文件名:httpd-2.4.41-o111c-x64-vc15-r2.7z 文件大小:6.1MB 下载链接:https://ww ...

  2. python socket简介

    一.socket是什么 socket是应用层与TCP/IP协议通信的中间软件抽象层,它是一组接口.在设计模式中,socket其实就是一个门面模式,它把复杂的TCP/IP协议隐藏在socket接口后面, ...

  3. 7.4 private 成员变量的私有

    /* * 学生类(age不能为负数.将age参数私有,创建方法判断age不为负.被private修饰的成员只能在本类中被访问,若想访问可以使用get.set方法) * * 通过对象直接访问成员变量,会 ...

  4. String 对象-->substr() 方法

    1.定义和用法 substr() 方法可在字符串中抽取从 开始 下标开始的指定数目的字符. 语法: string.substr(start,length) 参数: start:提取开始下标 lengt ...

  5. 七、环回接口ip地址(逻辑接口)

    loopback接口,在网络设备(一般是路由器)上是一种特殊的接口,它不是物理接口,而是一种看不见摸不着的逻辑接口(也称虚拟接口),但是对于网络设备来说却是至关重要的. 在网络设备上可以通过配置命令来 ...

  6. SpringMVC框架详细教程(六)_HelloWorld

    HelloWorld 在src下创建包com.pudding.controller,然后创建一个类HelloWorldController: package com.pudding.controlle ...

  7. tf.nn.bias_add 激活函数

    tf.nn.bias_add(value,bias,data_format=None,name=None) 参数: value:一个Tensor,类型为float,double,int64,int32 ...

  8. Redis分布式锁的实现以及工具类

    一.应用场景: 本文应用的场景为在查询数据时,发现数据不存在此时就需要去查询数据库并且更新缓存,此时可能存在高并发的请求同时打在数据库上,而针对这种情况必须要给这些请求加锁,故而采用了分布式锁的方式. ...

  9. 2019-07-31【机器学习】无监督学习之聚类 K-Means算法实例 (图像分割)

    样本: 代码: import numpy as np import PIL.Image as image from sklearn.cluster import KMeans def loadData ...

  10. 2019-07-25【机器学习】无监督学习之聚类 K-Means算法实例 (1999年中国居民消费城市分类)

    样本 北京,2959.19,730.79,749.41,513.34,467.87,1141.82,478.42,457.64天津,2459.77,495.47,697.33,302.87,284.1 ...