309302: CF1659F. Tree and Permutation Game
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Tree and Permutation Game
题意翻译
给定一个 $n$ 个节点的树和一个 $1\sim n$ 的排列 $p$,树的节点 $x$ 上有一个棋子。 小 A 和小 B 根据树和排列进行博弈,小 A 先手。 轮到小 A 时,小 A 必须选择两个不同的整数 $u,v(1\leq u,v\leq n)$,满足树上的棋子既不在节点 $u$ 又不在节点 $v$ 上。接着找到 $p_x=u,p_y=v$,然后交换 $p_x,p_y$ 的值。 轮到小 B 时,小 B 必须将棋子移到与其所在节点相邻的任意节点上。 小 A 的目标是将 $p$ 从小到大排序,小 B 的目标是避免小 A 达成目标。 你需要判断,当双方采取最优策略时,小 A 能否在有限步内完成自己的目标。能输出 `Alice`,否则输出 `Bob`。 每个测试点包含 $T$ 组数据。 保证: $1\leq T\leq10^3;$ $3\leq n,\sum n\leq2\times10^5;1\leq p_i,x\leq n;$ $p$ 是一个 $1\sim n$ 的排列。题目描述
There is a tree of $ n $ vertices and a permutation $ p $ of size $ n $ . A token is present on vertex $ x $ of the tree. Alice and Bob are playing a game. Alice is in control of the permutation $ p $ , and Bob is in control of the token on the tree. In Alice's turn, she must pick two distinct numbers $ u $ and $ v $ (not positions; $ u \neq v $ ), such that the token is neither at vertex $ u $ nor vertex $ v $ on the tree, and swap their positions in the permutation $ p $ . 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 $ p $ , and the vertex $ x $ on which the token initially is, find the winner of the game.输入输出格式
输入格式
The first line contains a single integer $ t $ ( $ 1 \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 $ n $ and $ x $ ( $ 3 \leq n \leq 2 \cdot 10^5 $ ; $ 1 \leq x \leq n $ ). Each of the next $ n-1 $ lines contains two integers $ a $ and $ b $ ( $ 1 \le a, b \le n $ , $ a \neq b $ ) indicating an undirected edge between vertex $ a $ and vertex $ b $ . It is guaranteed that the given edges form a tree. The next line contains $ n $ integers $ p_1, p_2, \ldots, p_n $ ( $ 1 \le p_i \le n $ ) — the permutation $ p $ . The sum of $ n $ over all test cases does not exceed $ 2 \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