CF1110G Tree-Tac-Toe

CF1110G Tree-Tac-Toe

题目描述

链接

Solution

大概就是分情况讨论一下吧

没想到中间是奇数时先手能必胜

还是太菜了

#include<bits/stdc++.h>

using namespace std;

inline int read()
{
    int f = 1 ,x = 0;
    char ch;
    do
    {
        ch = getchar();
        if(ch == '-') f = -1;
    }while(ch < '0' || ch > '9');
    do
    {
        x = (x<<3) + (x<<1) + ch - '0';
        ch = getchar();
    }while(ch >= '0'&&ch <= '9');
    return f*x;
}

const int MAXN = 5e5 + 10;
int T;
int n;
int d[MAXN];
vector<int>G[MAXN];
int son[MAXN];
char s[MAXN];

int main()
{
    T = read();
    while(T--)
    {
        for(int i=1;i<=n;i++) son[i] = 0,d[i] = 0,G[i].clear();
        n = read();
        int cnt = 0,tot = n;
        for(register int i=1;i<n;i++)
        {
            int u = read(),v = read();
            G[u].push_back(v);
            G[v].push_back(u);
            d[u]++;d[v]++;
        }
        scanf("%s",s+1);
        for(register int i=1;i<=n;i++)
        {
            if(s[i] == 'W') 
            {
                d[i]++;
                son[i]++;
                tot += 3;
                cnt++;
            }
        }
        for(register int i=1;i<=n;i++)
        {
            for(register int j=0;j<G[i].size();j++)
            {
                int v = G[i][j];
                if(d[v] > 1)
                    son[i]++;
            }
        }
        bool flag = 0;
        for(register int i=1;i<=n;i++)
        {
            if((d[i]>=4))
            {
                flag = 1;
                printf("White\n");
                break;
            }
            else if(d[i]>=3&&son[i]>=2)
            {
                flag = 1;
                printf("White\n");
                break;
            }
            if(d[i]==3) cnt++;
        }
        if(flag) continue;
        if(cnt == 2)
        {
            if(tot & 1) printf("White\n");
            else printf("Draw\n");
        }
        else printf("Draw\n");
    }
}

 

posted @ 2020-10-15 17:01  wlzs1432  阅读(76)  评论(0编辑  收藏  举报