We consider a set of integers $$$S$$$ to be anti-closed if there do not exist elements $$$x$$$, $$$y$$$ and $$$z$$$ in $$$S$$$ where $$$x+y=z$$$ ($$$x$$$, $$$y$$$ and $$$z$$$ do not necessarily have to be distinct).
For example:
You are given an array $$$a$$$ of $$$n$$$ distinct integers. Partition it into at most $$$60$$$ anti-closed subsequences. Formally, find an array $$$b$$$ of size $$$n$$$ such that
It can be shown that a solution always exists.
The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the size of the array $$$a$$$.
The next line of the input contains $$$n$$$ distinct integers $$$a_1, a_2 \cdots a_n$$$ ($$$1 \le a_i \le 10^{18}$$$) — the elements of the array $$$a$$$.
Output $$$n$$$ integers $$$b_1, b_2, \cdots b_n$$$ ($$$1 \le b_i \le 60$$$), representing the partition of $$$a$$$, as described above.
If there are multiple solutions, print any.
151 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 2 2 1 3 1 3 3 2 2 4 4 4 2 1
3250000000000000000 500000000000000000 1000000000000000000
1 2 3
For the first test case, the input array is partitioned into these subsequences:
We can show that each of these sets is anti-closed.
You have a hand of cards, where each card has one of $$$n$$$ types. For each $$$i$$$ from $$$1$$$ to $$$n$$$, you have $$$a_i$$$ cards with type $$$i$$$, and the bank has infinite cards with type $$$i$$$.
You can perform the following trade with the bank any number of times:
Choose any two cards with the same type from your hand, and exchange them for a single card from the bank with any type except the type of the cards you just exchanged. Note that the bank only has cards with types $$$1$$$ through $$$n$$$, so you cannot trade for cards with any other types.
For example, here is a valid sequence of trades on the first sample case:
What is the maximum number of trades you can perform?
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot 10^5$$$) — the number of card types.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2 \cdots a_n$$$ ($$$0 \le a_i \le 10^9$$$), where $$$a_i$$$ is the number of cards of type $$$i$$$ that you currently have.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print a single integer — the maximum number of trades you can perform.
942 0 0 125 261 5 0 6 7 141 1 0 124 271 2 4 8 4 2 121 140 0 0 031000000000 1000000000 1000000000
2 5 19 0 5 21 0 0 2999999999
The diagram above describes an optimal sequence of trades in the first test case.
In the fourth test case, it is impossible to perform any trades, since you don't start with any pair of cards with the same type, so the answer is $$$0$$$.
You are given an array $$$a$$$ of $$$n$$$ integers. A sub-array $$$[a_l, a_{l+1}, \cdots a_r]$$$ is considered end-balanced if $$$l \lt r$$$ and $$$a_l + a_r = a_{l+1} + ... + a_{r-1}$$$.
For example, the subarrays $$$[4, 9, 5]$$$, $$$[-1, 3, 5, 9]$$$, and $$$[0, 0]$$$ are considered end-balanced, and the subarrays $$$[0]$$$, $$$[-2, -3, -5]$$$, and $$$[1, 1]$$$ are not.
How many subarrays of $$$a$$$ are end-balanced?
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot 10^5$$$) — the size of the array $$$a$$$.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2 \cdots a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print a single integer — the number of end-balanced subarrays of $$$a$$$.
751 2 3 4 530 0 04-10 5 -5 1062 2 2 2 2 271 0 1 0 1 0 151000000000 1000000000 1000000000 1000000000 10000000001-1000000000
2 3 2 3 5 2 0
The end-balanced subarrays in the first test case are:
The end-balanced subarrays in the second test case are:
The end-balanced subarrays in the third test case are:
You are given a tree on $$$n$$$ nodes rooted at node $$$1$$$. A spider and a fly are in the tree. The spider has three legs which are initially on nodes $$$a$$$, $$$b$$$, and $$$c$$$. The fly is on node $$$f$$$ and does not move.
Some nodes are considered to be in the shadow of the spider. A node is in the shadow of the spider if it lies on any of the three shortest paths between its legs, $$$a$$$–$$$b$$$, $$$a$$$–$$$c$$$, and $$$b$$$–$$$c$$$.
The spider can move its legs from vertices $$$a$$$, $$$b$$$, $$$c$$$ to vertices $$$a'$$$, $$$b'$$$, $$$c'$$$ if the size of its shadow remains constant and $$$\max\{\textrm{dist}(a, a'), \textrm{dist}(b, b'), \textrm{dist}(c, c')\}\leq 1$$$. The function $$$\textrm{dist}(u,\,v)$$$ indicates the number of edges on the shortest path between nodes $$$u$$$ and $$$v$$$ in the tree.
For example, here is one possible sequence of two moves by a spider with $$$6$$$ nodes in its shadow. The vertices that have a red outline are in the shadow of the spider, and the vertices that are colored red are the spider's legs.
The spider eats through its legs. Determine whether the spider can move any of its legs to the fly's location, after any number of moves (possibly zero).
The first line of the input contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$) — the number of vertices in the tree.
The next line of each test case contains $$$n-1$$$ integers $$$p_2,\,p_3,\,\ldots,\,p_n$$$ ($$$1 \le p_i \lt i$$$) — the parents of each vertex in the tree, except the root.
The next line of each test case contains three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1\leq a,\,b,\,c\leq n$$$) — the initial positions of each of the spider's legs.
The fourth and final line of each test case contains an integer $$$f$$$ ($$$1\leq f\leq n$$$) — the position of the fly.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print "YES" if the spider is able to catch the fly, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
7212 2 2161 1 3 1 52 4 5161 1 3 1 52 4 61181 2 3 2 5 3 1 7 7 7 4 2 12 4 12 4 1512 15 1216121 1 3 4 5 5 7 4 9 10 91 6 1112121 1 3 4 5 5 7 4 9 10 91 6 114121 1 3 4 5 5 7 4 9 10 91 6 116
Yes Yes No Yes Yes No Yes
In the first test case, all legs of the spider are initially on vertex $$$2$$$, so that is the only vertex in the shadow. By moving all legs to vertex $$$1$$$ at the same time, the spider can reach the food while keeping its shadow the same size.
In the second test case, the spider can use this move to reach the food with one of its legs:
In the third test case, the food is located at vertex $$$1$$$, which is in the shadow of the spider, but the spider cannot move any of its legs to the food:
You are faced with a combination lock that consists of an $$$n$$$ by $$$m$$$ grid of dials. A $$$k$$$-dial is a dial that can display values $$$0, 1, \cdots k-1$$$. A $$$k$$$-dial currently displaying value $$$v$$$ can be incremented to make it display value $$$(v + 1)\mod k$$$.
This particular lock consists of $$$3$$$-dials and $$$5$$$-dials in a checkerboard arrangement, with the top left dial being a $$$3$$$-dial. In a single move, you can increment a dial and all of its horizontal and vertical neighbors.
For example, here is one possible sequence of moves on a grid with $$$n=3$$$, $$$m=4$$$ (where $$$3$$$-dials are gray and $$$5$$$-dials are white):
Initially, all of the dials are displaying $$$0$$$. You remember what positions the dials must be in for the lock to open, but you forgot the combination of moves to reach it. Find a sequence of moves that sets all dials to the correct positions. You do not need to minimize the number of moves, but you can use no more than $$$20nm$$$ moves.
It can be shown that such a solution always exists.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the number of rows and columns in the grid, respectively.
The $$$i$$$-th of the next $$$n$$$ lines contains $$$m$$$ integers describing the $$$i$$$-th row of the combination. The $$$j$$$-th of these is $$$a_{ij}$$$, the desired position of the dial at position $$$(i, j)$$$. If $$$i+j$$$ is even, $$$0 \le a_{ij} \lt 3$$$. Otherwise, $$$0 \le a_{ij} \lt 5$$$.
It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases does not exceed $$$10^4$$$.
The first line of output for each test case should contain a single integer $$$k$$$ ($$$0 \le k \le 20nm$$$) — the number of moves you will perform.
The next $$$k$$$ lines of output should each contain integers $$$i$$$ and $$$j$$$, indicating that the next move will be performed at position $$$(i, j)$$$.
If there are multiple solutions, print any.
53 30 1 01 1 10 1 02 30 0 00 0 03 50 1 2 3 00 1 4 0 20 0 1 2 01 112 22 44 2
1 2 2 0 4 1 3 2 4 2 4 2 3 1 1 1 4 1 1 1 1 2 2 2 2
Here is the move used in the first sample case:
In the second sample case, the lock is already in the target position, so no moves are needed.
We define a bitwise triangle to be a triplet of distinct integers $$$(a,\,b,\,c)$$$ with $$$a\&b\neq0$$$, $$$a\&c\neq0$$$, and $$$b\&c\neq0$$$, where $$$\&$$$ indicates the bitwise AND operator.
You are given an integer $$$n$$$. We define a triangle packing to be a set of pairwise disjoint bitwise triangles consisting of integers from $$$1$$$ to $$$n$$$ inclusive. Find a maximal triangle packing (one with the maximum number of bitwise triangles).
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
Each test case consists of a single line containing one integer $$$n$$$ ($$$1 \le n \le 2\cdot 10^5$$$) — the maximum allowed number in any of the triangles.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
The first line of output for each test case should contain a single integer $$$k$$$ ($$$0 \le k \le n$$$) — the size of the maximal triangle packing.
The next $$$k$$$ lines of output should each contain three distinct integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le n$$$), representing one triangle of the maximal triangle packing.
If there are multiple solutions, print any.
6456101814
0 1 1 3 5 1 1 3 5 3 1 3 5 8 9 10 2 6 7 6 1 5 15 6 7 13 2 3 10 4 12 14 8 9 11 16 17 18 4 1 5 11 8 9 10 2 3 6 4 7 12
In the first test case, we have $$$n=4$$$. It can be shown that we cannot create any bitwise triangles from the set $$$\{1, 2, 3, 4\}$$$, so the size of the maximal packing is $$$0$$$.
In the second test case, we have $$$n=5$$$. The given triangle packing is valid since each of the three numbers in the one bitwise triangle are odd, and therefore the bitwise AND of any two of them is nonzero. It can be shown that this packing is maximal for $$$n=5$$$.
Two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ are considered to be a knight-move apart if exactly one of the following conditions holds:
Notice that this definition closely matches how a knight moves in chess. For example, here are three pairs of points that are a knight-move apart:
You are given integers $$$p$$$ and $$$q$$$. Find a simple lattice polygon whose area is $$$p/q$$$, where each pair of adjacent vertices is a knight-move apart, or state that no such polygon exists.
A polygon is simple if there are exactly two edges touching each vertex, and no two edges of the polygon intersect except at its vertices. A polygon is a lattice polygon if the coordinates of each of its vertices are integers.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10$$$) — the number of test cases. The description of the test cases follows.
Each test case consists of a single line containing two integers $$$p$$$ and $$$q$$$ ($$$1 \le p, q \le 10^4$$$) — the numerator and denominator of the desired area, respectively.
For each test case, if there is no solution, output a single integer $$$-1$$$.
Otherwise, the first line of output for each test case should contain a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — the number of vertices in your polygon.
The next $$$n$$$ lines of output should each contain two integers $$$x$$$ and $$$y$$$ ($$$-10^9 \le x, y \le 10^9$$$) — the vertices of your polygon in either clockwise or counterclockwise order.
Your polygon should be simple, have an area of $$$\frac{p}{q}$$$, and each pair of adjacent vertices should be a knight-move apart.
If there are multiple solutions, print any.
418 31 28 120 3
6 0 0 2 1 1 3 0 1 -1 3 -2 1 -1 14 -1 -2 -3 -1 -2 1 -1 3 0 1 1 3 2 1 3 -1 1 -2 2 0 1 2 0 0 -1 2 -2 0 -1
Here is the polygon described by the output of the first test case, with an area of $$$\frac{18}{3} = 6$$$:
Here is the polygon described by the output of the third test case, with an area of $$$\frac{8}{1} = 8$$$:
For the second and fourth test cases, we can show that no valid polygon exists.
There are $$$n$$$ lights in a row, all initially deactivated. Some lights, when activated, will illuminate themselves and all lights to their left. The others, when activated, will illuminate themselves and all lights to their right.
This image shows the result of activating the fourth light (and nothing else) in the first sample case. The first four lights are illuminated, and everything else is not.
You have already figured out the minimum number of lights that need to be activated to illuminate everything, but now, you're wondering how many good subsets of lights exist.
A subset $$$S$$$ of the lights is considered good if when you activate the lights in $$$S$$$ (and only the lights in $$$S$$$), every light on the row is illuminated.
How many good subsets are there? Since the answer may be large, output it modulo $$$10^9+7$$$.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot 10^5$$$) — the number of lights.
The next line of each test case contains a string $$$s$$$ consisting of $$$n$$$ characters L and R, indicating whether the lights are pointed to the left or right.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print a single integer — the number of good subsets, taken modulo $$$10^9+7$$$.
76LRRLRL1L2RL2LR5RRRRL10LRLRLRLRLR31LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
50 1 3 1 24 912 73741817
For the second and fourth test cases, the only way to illuminate everything is to activate every light. Therefore, for these cases, the only good subset is the set containing all lights.
For the third test case, as long as either of the two lights is activated, everything will be illuminated. Therefore, the sets $$$\{1\}$$$, $$$\{2\}$$$, and $$$\{1, 2\}$$$ are good.
There is an $$$n$$$ by $$$m$$$ grid of black and white squares. In one operation, you can pick any two adjacent squares of the same color and swap the colors of both. For example, here is a valid sequence of two operations on a grid with $$$n=4$$$, $$$m=3$$$:
You are also given a target grid of $$$n$$$ by $$$m$$$ black and white squares. Perform at most $$$200nm$$$ operations on the starting grid to reach the target grid, or state that it is impossible to do so. You do not need to minimize the number of operations.
It can be shown that if there is a solution, there is one that uses at most $$$200nm$$$ operations.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 50$$$) — the number of rows and columns in the grid, respectively.
The $$$i$$$-th of the next $$$n$$$ lines contains $$$m$$$ characters describing the $$$i$$$-th row of the starting grid. The $$$j$$$-th of these is '#' if the square at position $$$(i, j)$$$ is black, and '.' if the square at position $$$(i, j)$$$ is white.
The next $$$n$$$ lines describe the target grid in the same format as the starting grid.
It is guaranteed that the sum of $$$n\cdot m$$$ over all test cases does not exceed $$$2500$$$.
For each test case, if there is no solution, output a single integer $$$-1$$$.
Otherwise, the first line of output for each test case should contain a single integer $$$k$$$ ($$$0 \le k \le 200nm$$$) — the number of operations you will perform.
The next $$$k$$$ lines of output should each contain four integers $$$i_1$$$, $$$j_1$$$, $$$i_2$$$, and $$$j_2$$$ ($$$1 \le i_1, i_2 \le n$$$, $$$1 \le j_1, j_2 \le m$$$) — the two adjacent squares $$$(i_1, j_1)$$$ and $$$(i_2, j_2)$$$ that are part of this operation.
If there are multiple solutions, print any.
63 3..#.#..#.#.#..#.##4 6#.#.#..#.#.##.#.#..#.#.#........................1 1##4 5#...#...#.###.#....#..#.#.#...###.#.##.#1 8...#............4 2........########
3 1 1 1 2 1 2 2 2 2 3 3 3 -1 0 5 1 2 1 3 2 2 2 3 1 1 1 2 2 3 2 4 4 2 4 3 -1 4 1 1 1 2 4 1 4 2 2 1 3 1 2 2 3 2
Here is the sequence of $$$3$$$ operations described by the output of the first test case:
It is impossible to perform any operations in the second test case, so it is not possible to reach the target grid.
You want to find two permutations $$$p$$$ and $$$q$$$ of size $$$n$$$ that satisfy $$$m$$$ restrictions of the form $$$(p_i-p_j)\cdot (q_i-q_j) \gt 0$$$.
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2, 3, 1, 5, 4]$$$ is a permutation, but $$$[1, 2, 2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1, 3, 4]$$$ is also not a permutation ($$$l=3$$$ but there is $$$4$$$ in the array).
Find two distinct permutations $$$p$$$ and $$$q$$$ of size $$$n$$$ such that all restrictions are satisfied, or state that it is impossible to do so. $$$p$$$ and $$$q$$$ are considered distinct if there is at least one index $$$i$$$ where $$$p_i \neq q_i$$$.
The first line of the input contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1\leq n\leq 2\cdot 10^5$$$, $$$0 \le m \le min(2\cdot 10^5, \frac{n(n-1)}{2})$$$) — the size of the permutations and the number of restrictions, respectively.
Each of the next $$$m$$$ lines of the test case contains two integers $$$i$$$ and $$$j$$$ ($$$1 \le i \lt j \le n$$$) — representing the restriction $$$(p_i-p_j)\cdot (q_i-q_j) \gt 0$$$. It is guaranteed that all restrictions in the input are distinct.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
Similarly, the sum of $$$m$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
The first line of output for each test case should contain "YES" if a valid $$$p$$$ and $$$q$$$ exist, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
If you printed "YES", print two additional lines of output.
The first of these should contain $$$n$$$ distinct integers $$$p_1,\, p_2, \cdots\, p_n$$$ ($$$1 \le p_i \le n$$$) — the permutation $$$p$$$.
The second of these should contain $$$n$$$ distinct integers $$$q_1,\, q_2,\, \cdots\, q_n$$$ ($$$1 \le q_i \le n$$$) — the permutation $$$q$$$.
31 02 02 11 2
No Yes 1 2 2 1 No
25 81 41 52 32 42 53 43 54 54 31 21 31 4
Yes 5 3 4 1 2 4 3 5 1 2 Yes 1 3 4 2 1 2 3 4
15 101 21 31 41 52 32 42 53 43 54 5
No
In the first test case of the first test, $$$n=1$$$. Since there is only one distinct permutation of size $$$1$$$, there is no solution.
In the second test case of the first test, $$$n=2$$$ and there are no restrictions that need to be satisfied. So $$$p = [1,\, 2]$$$ and $$$q = [2,\,1]$$$ is a valid solution.
Alice and Bob are playing a game on a tree rooted at node 1. A token is placed on the root then the players take turns making moves with Alice moving first. During a move a player must move the token from the node its on to one of that node's children. If there are no legal moves available, then the player whose turn it is will lose.
Since Alice and Bob are too good at this game they decided to play a modified version of the game. Before the game begins, Alice can add a single directed edge $$$(u, v)$$$ to the tree. Then, during the game, if the token is on vertex $$$u$$$ and the extra edge is present, the current player can choose to move the token to vertex $$$v$$$ and delete the extra edge (preventing it from being used multiple times in one game).
Of the $$$n^2$$$ possible pairs $$$(u, v)$$$ Alice can choose, how many will allow Alice to win the game assuming both players play optimally? Note that $$$u=v$$$ is allowed, as are $$$(u, v)$$$ pairs that match an existing edge in the tree (in either direction).
The first line of the input contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$) — the number of vertices in the tree.
The next line of each test case contains $$$n-1$$$ integers $$$p_2,\,p_3,\,\ldots,\,p_n$$$ ($$$1 \le p_i \lt i$$$) — the parents of each vertex in the tree, except the root.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print a single integer — the number of $$$(u, v)$$$ pairs that will allow Alice to win, assuming both players play optimally.
431 261 1 3 3 561 2 3 4 551 1 1 1
4 33 27 25
For the first test test case, here are the $$$4$$$ edges Alice can add to give herself the winning strategy:
There is an $$$n$$$ by $$$m$$$ grid of white squares. You want to place a $$$k$$$ by $$$k$$$ red square and a $$$k$$$ by $$$k$$$ blue square on this grid such that they do not overlap. For example, here is a valid solution for $$$n=6$$$, $$$m=8$$$, $$$k=3$$$:
How many ways are there to do this? Two ways are considered different if at least one square is a different color in each.
Since the answer may be large, output it modulo $$$10^9+7$$$.
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The description of the test cases follows.
Each test case consists of a single line containing three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n, m \le 10^9$$$, $$$1 \le k \le \min(n, m)$$$) — the number of rows and columns in the grid, and the side length of the squares, respectively.
For each test case, print a single integer — the number of ways to place both squares in the grid, taken modulo $$$10^9+7$$$.
61 2 14 3 33 4 210 10 313 9 41000000000 1000000000 12345678
2 0 8 2940 1860 547313402
The solutions for the first test case are:
In the second test case, there is no way to fit both squares inside the rectangle.
The solutions for the third test case are:
There were too many constructive problems in this contest, so we decided to set a standard data structure problem.
You are given a tree with $$$n$$$ labeled nodes. Each node also has a blank value initially.
The longest increasing tree subsequence between two nodes $$$(u, v)$$$ on the tree is computed as follows:
You are given $$$n$$$ updates, $$$x_1, x_2 \dots x_n$$$. For update $$$i$$$, fill in the value $$$i$$$ at node $$$x_i$$$. After each update, compute the longest longest increasing tree subsequence among all pairs of nodes $$$(u, v)$$$ in the tree.
It is guaranteed that all $$$x_i$$$ values are distinct.
$$$^\dagger$$$ Define a sequence of integers $$$a_i...a_m$$$. A subsequence $$$a_{i_1}, a_{i_2}, ..., a_{i_k}$$$ where $$$1 \leq i_1 \lt i_2 \lt \cdots \lt i_k \leq m$$$ is called increasing if $$$a_{i_1} \lt a_{i_2} \lt a_{i_3} \lt ... \lt a_{i_k}$$$. An increasing subsequence is called longest if it has maximum length among all increasing subsequences.
The first line of the input contains an integer $$$1 \leq t \leq 10^4$$$, denoting the number of test cases.
The first line of each test case contains one integer $$$2 \leq n \leq 5 \cdot 10^5$$$.
The next $$$n - 1$$$ lines contain two integers $$$1 \leq u, v \leq n$$$, denoting an undirected edge between the nodes with labels $$$u$$$ and $$$v$$$, respectively. It is guaranteed that the input edges form a tree.
The last line of input for the testcase consists of $$$n$$$ integers $$$x_1...x_n$$$, denoting the updates in order. It is guaranteed that all $$$x_i$$$ values are distinct.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$5 \cdot 10^5$$$.
For each test case, print $$$n$$$ space-separated integers on a single line, denoting the answer after the $$$i^\textrm{th}$$$ update.
451 22 33 44 53 1 5 2 4105 13 43 63 78 35 82 59 29 103 6 9 4 5 2 1 8 10 71510 13 413 53 78 315 812 139 122 911 211 146 1110 610 159 2 10 5 13 14 7 15 11 12 1 6 8 3 421 21 2
1 2 2 2 3 1 2 2 2 2 3 3 3 4 4 1 2 3 3 3 3 4 4 4 4 4 4 5 6 7 1 2
Remember that the updates tell you the value of the $$$x_i^\textrm{th}$$$ node, not that the value of node $$$i$$$ is $$$x_i$$$.
An example of the process for the first tree is shown below. The yellow nodes are one potential longest increasing tree subsequence after each operation. The node's labels are 1-5 from left to right, initially with blank values.
You are given two strings $$$s$$$ and $$$t$$$. In one operation, you can delete all the odd-indexed characters from $$$s$$$ or all the even-indexed characters from $$$s$$$.
For example, if you perform an operation on the string abcdefg, you could choose to turn it into aceg or bdf.
After performing any number of operations on $$$s$$$ (including zero), is it possible for $$$s$$$ to equal $$$t$$$?
The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a string $$$s$$$ ($$$1 \le |s| \le 2\cdot 10^5$$$) of lowercase letters — the starting string, as described above.
The second line of each test case contains a string $$$t$$$ ($$$1 \le |t| \le 2\cdot 10^5$$$) of lowercase letters — the desired ending string, as described above.
It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$2\cdot 10^5$$$. Similarly, the sum of $$$|t|$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print "YES" if it is possible to make all $$$s$$$ equal to $$$t$$$ after any number of operations, and "NO" otherwise.
You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.
6tjhdoumraisethomasnickjamesbaccbabaccbaabcdefgcdeabcdabcdaaabcdabcdbc
YES NO YES NO YES NO
In the first test case, by removing all even-indexed characters of $$$s$$$, we obtain $$$s = thomas$$$, so we have $$$s = t$$$.
In the second test case, the length of $$$s$$$ is less than the length of $$$t$$$, and if we perform any operations, the length of $$$s$$$ will only decrease. Therefore, $$$s$$$ can never equal $$$t$$$.
In the third test case, we have $$$s = t$$$ even before performing any operations.