CF1659F.Tree and Permutation Game

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There is a tree of nn vertices and a permutation pp of size nn . A token is present on vertex xx of the tree.

Alice and Bob are playing a game. Alice is in control of the permutation pp , and Bob is in control of the token on the tree. In Alice's turn, she must pick two distinct numbers uu and vv (not positions; uvu \neq v ), such that the token is neither at vertex uu nor vertex vv on the tree, and swap their positions in the permutation pp . In Bob's turn, he must move the token to an adjacent vertex from the one it is currently on.

Alice wants to sort the permutation in increasing order. Bob wants to prevent that. Alice wins if the permutation is sorted in increasing order at the beginning or end of her turn. Bob wins if he can make the game go on for an infinite number of moves (which means that Alice is never able to get a sorted permutation). Both players play optimally. Alice makes the first move.

Given the tree, the permutation pp , and the vertex xx on which the token initially is, find the winner of the game.

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases. The description of each test case follows.

The first line of each test case has two integers nn and xx ( 3n21053 \leq n \leq 2 \cdot 10^5 ; 1xn1 \leq x \leq n ).

Each of the next n1n-1 lines contains two integers aa and bb ( 1a,bn1 \le a, b \le n , aba \neq b ) indicating an undirected edge between vertex aa and vertex bb . It is guaranteed that the given edges form a tree.

The next line contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n ( 1pin1 \le p_i \le n ) — the permutation pp .

The sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output one line containing Alice or Bob — the winner of the game. The output is case-sensitive.

输入输出样例

  • 输入#1

    3
    6 3
    1 3
    3 2
    4 3
    3 6
    5 3
    2 1 3 6 4 5
    3 2
    1 2
    3 2
    1 3 2
    3 2
    1 2
    3 2
    1 2 3

    输出#1

    Alice
    Bob
    Alice
  • 输入#2

    1
    11 4
    3 11
    5 9
    10 3
    4 8
    2 4
    1 8
    6 8
    8 7
    4 5
    5 11
    7 4 9 8 6 5 11 10 2 3 1

    输出#2

    Alice

说明/提示

Here is the explanation for the first example:

In the first test case, there is a way for Alice to win. Here is a possible sequence of moves:

  1. Alice swaps 55 and 66 , resulting in [2,1,3,5,4,6][2,1,3,5,4,6] .
  2. Bob moves the token to vertex 55 .
  3. Alice swaps 11 and 22 , resulting in [1,2,3,5,4,6][1,2,3,5,4,6] .
  4. Bob moves the token to vertex 33 .
  5. Alice swaps 44 and 55 , resulting in [1,2,3,4,5,6][1,2,3,4,5,6] , and wins.

In the second test case, Alice cannot win since Bob can make the game go on forever. Here is the sequence of moves:

  1. Alice can only swap 11 and 33 , resulting in [3,1,2][3,1,2] .
  2. Bob moves the token to vertex 11 .
  3. Alice can only swap 22 and 33 , resulting in [2,1,3][2,1,3] .
  4. Bob moves the token to vertex 22 .
  5. Alice can only swap 11 and 33 , resulting in [2,3,1][2,3,1] .
  6. Bob moves the token to vertex 33 .
  7. Alice can only swap 11 and 22 , resulting in [1,3,2][1,3,2] .
  8. Bob moves the token to vertex 22 .

And then the sequence repeats forever.In the third test case, Alice wins immediately since the permutation is already sorted.

首页