• ACM-ICPC 2019 山东省省赛D Game on a Graph


    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;
        }
    }
    
  • 相关阅读:
    使用jQuery淡入淡出HTML文本效果
    php一个诡异而简单的错误
    Android Tasker应用之自动查询并显示话费流量套餐信息
    ListView在应用开发中较为常用的做法
    网址收藏(网页制作源码下载网址、后台源码下载网址、域名注册网址)
    Flex4事件的监听与发布
    收拾心情,安安静静的学习
    ASP.NET development sever 在Windows server 2008/Vista显示页面无法找到 [转帖]
    花点时间搞清top、postop、scrolltop、scrollHeight、offsetHeight[转帖]
    HTTP 错误 401.2 Unauthorized 由于身份验证头无效,您无权查看此页。 IIS7.0解决办法
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12798963.html
Copyright © 2020-2023  润新知