CF1110G.Tree-Tac-Toe

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The tic-tac-toe game is starting on a tree of nn vertices. Some vertices are already colored in white while the remaining are uncolored.

There are two players — white and black. The players make moves alternatively. The white player starts the game. In his turn, a player must select one uncolored vertex and paint it in his color.

The player wins if he paints some path of three vertices in his color. In case all vertices are colored and neither player won, the game ends in a draw.

Could you please find who will win the game or whether it ends as a draw, assuming both players play optimally?

井字棋游戏将在一棵包含 nn 个顶点的树上进行。其中一些顶点已被染成白色,其余顶点尚未染色。

游戏有两个玩家:白方和黑方。双方轮流行动,白方先手。在自己的回合中,玩家必须选择一个未染色的顶点,并将其染成自己的颜色。

若某位玩家成功将某条长度为三的路径上的所有三个顶点都染成自己的颜色,则该玩家获胜。若所有顶点均被染色后仍无玩家获胜,则游戏以平局结束。

假设双方均采取最优策略,请判断哪位玩家将获胜,或游戏是否将以平局结束。

输入格式

The first line contains a single integer TT (1≤T≤50 0001 \le T \le 50\,000) — the number of test cases. Then descriptions of TT test cases follow.

The first line of each test contains a single integer nn (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5) — the number of vertices in the tree.

Each of the following n−1n - 1 lines contains integers vv, uu (1≤v,u≤n1 \le v, u \le n) denoting an edge of the tree connecting vertices vv and uu.

The last line of a test case contains a string of letters 'W' (for white) and 'N' (for not colored) of length nn denoting already colored vertices. Vertexes already colored in white are denoted as 'W'.

It's guaranteed that the given edges form a tree, that there is at least one uncolored vertex and that there is no path of three white vertices.

It's guaranteed that sum of all nn among all test cases is at most 5⋅1055 \cdot 10^5.

第一行包含一个整数 TT(1≤T≤50 0001 \le T \le 50\,000),表示测试用例的数量。随后是 TT 个测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5),表示树中顶点的数量。

接下来的 n−1n - 1 行每行包含两个整数 vv、uu(1≤v,u≤n1 \le v, u \le n),表示树中连接顶点 vv 和 uu 的一条边。

测试用例的最后一行是一个长度为 nn 的字符串,由字符 'W'(表示白色)和 'N'(表示未着色)组成,用于表示已着色的顶点。已被着色为白色的顶点用 'W' 表示。

保证所给边构成一棵树,至少存在一个未着色顶点,且不存在长度为三的全白顶点路径。

保证所有测试用例的 nn 值之和不超过 5⋅1055 \cdot 10^5。

输出格式

For every test case, print either "White", "Draw" or "Black", depending on the result of the game.

对于每个测试用例,根据游戏结果输出“White”、“Draw”或“Black”。

输入输出样例

  • 输入#1

    2
    4
    1 2
    1 3
    1 4
    NNNW
    5
    1 2
    2 3
    3 4
    4 5
    NNNNN

    输出#1

    White
    Draw

说明/提示

In the first example, vertex 44 is already colored in white. The white player can win by coloring the vertex 11 in white first and the remaining vertex on his second turn. The process is illustrated with the pictures below.

In the second example, we can show that no player can enforce their victory.

在第一个例子中,顶点 44 已被染成白色。白方玩家可以通过第一步将顶点 11 染成白色,第二步再将剩余的顶点染成白色来获胜。该过程如下图所示。

在第二个例子中,可以证明双方均无法强制获胜。

输入解题思路,AI测评打分。不知道怎么写?

首页