#x1015. CF1659F Tree and Permutation Game
CF1659F Tree and Permutation Game
Tree and Permutation Game
题面翻译
给定一个 个节点的树和一个 的排列 ,树的节点 上有一个棋子。
小 A 和小 B 根据树和排列进行博弈,小 A 先手。
轮到小 A 时,小 A 必须选择两个不同的整数 ,满足树上的棋子既不在节点 又不在节点 上。接着找到 ,然后交换 的值。
轮到小 B 时,小 B 必须将棋子移到与其所在节点相邻的任意节点上。
小 A 的目标是将 从小到大排序,小 B 的目标是避免小 A 达成目标。
你需要判断,当双方采取最优策略时,小 A 能否在有限步内完成自己的目标。能输出 Alice
,否则输出 Bob
。
每个测试点包含 组数据。
保证: 是一个 的排列。
题目描述
There is a tree of vertices and a permutation of size . A token is present on vertex of the tree.
Alice and Bob are playing a game. Alice is in control of the permutation , and Bob is in control of the token on the tree. In Alice's turn, she must pick two distinct numbers and (not positions; ), such that the token is neither at vertex nor vertex on the tree, and swap their positions in the permutation . 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 , and the vertex on which the token initially is, find the winner of the game.
输入格式
The first line contains a single integer ( ) — the number of test cases. The description of each test case follows.
The first line of each test case has two integers and ( ; ).
Each of the next lines contains two integers and ( , ) indicating an undirected edge between vertex and vertex . It is guaranteed that the given edges form a tree.
The next line contains integers ( ) — the permutation .
The sum of over all test cases does not exceed .
输出格式
For each test case, output one line containing Alice or Bob — the winner of the game. The output is case-sensitive.
样例 #1
样例输入 #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
样例输入 #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:
- Alice swaps and , resulting in .
- Bob moves the token to vertex .
- Alice swaps and , resulting in .
- Bob moves the token to vertex .
- Alice swaps and , resulting in , 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:
- Alice can only swap and , resulting in .
- Bob moves the token to vertex .
- Alice can only swap and , resulting in .
- Bob moves the token to vertex .
- Alice can only swap and , resulting in .
- Bob moves the token to vertex .
- Alice can only swap and , resulting in .
- Bob moves the token to vertex .
And then the sequence repeats forever.In the third test case, Alice wins immediately since the permutation is already sorted.