Codeforces round #625 editorial

Revision en1, by mohammedehab2002, 2020-02-25 06:43:11

1000A - Codehorses T-shirts

$$$a=1$$$ and $$$b=x-1$$$ always work.

1000B - Light It Up

Let the number of distinct elements in $$$a$$$ be called $$$d$$$. Clearly, the answer is limited by $$$d$$$. Now, you can construct your subsequence as follows: take the smallest element from the first copy, the second smallest element from the second copy, and so on. Since there are enough copies to take every element, the answer is $$$d$$$.

1000C - Covered Points Count

Notice that there will be a path that passes through the edge labeled $$$0$$$ and the edge labeled $$$1$$$ no matter how you distribute the weights, so there's always a path with $$$MEX$$$ $$$2$$$ or more. If any node has degree 3 or more, you can distribute the labels $$$0$$$, $$$1$$$, and $$$2$$$ to edges incident to this node and distribute the rest of the labels arbitrarily. Otherwise, the tree is a bamboo, and it doesn't actually matter how you distribute the labels, since there will be a path with $$$MEX$$$ $$$n-1$$$ anyway.

1000D - Yet Another Problem On a Subsequence

First, let's look at some special cases. If $$$u>v$$$ or $$$u$$$ and $$$v$$$ have different parities, there's no array. If $$$u=v=0$$$, the answer is an empty array. If $$$u=v \neq 0$$$, the answer is $$$[u]$$$. Now, the length is at least 2. Let $$$x=\frac{v-u}{2}$$$. The array $$$[u,x,x]$$$ satisfies the conditions, so the length is at most 3. We just need to figure out whether there's a pair of number $$$a$$$ and $$$b$$$. Such that $$$a \oplus b=u$$$ and $$$a+b=v$$$. Notice that $$$a+b=a \oplus b+2*(a$$$&$$$b)$$$, so we know that $$$a$$$&$$$b=\frac{v-u}{2}=x$$$ (surprise surprise.) The benefit of getting rid of $$$a+b$$$ and looking at $$$a$$$&$$$b$$$ instead is that we can look at $$$a$$$ and $$$b$$$ bit by bit. If $$$x$$$ has a one in some bit, $$$a$$$ and $$$b$$$ must both have ones, so $$$a \oplus b=u$$$ must have a 0. If $$$x$$$ has a zero, there are absolutely no limitation on $$$u$$$. So, if there's a bit where both $$$x$$$ and $$$u$$$ have a one, that is to say $$$x$$$&$$$u\neq0$$$, you can't find such $$$a$$$ and $$$b$$$, and the length will be 3. Otherwise, $$$x$$$&$$$u=0$$$ which means $$$x \oplus u=x+u$$$, so the array $$$[u+x,x]$$$ works. Can you see how this array was constructed? We took $$$[u,x,x]$$$ which more obviously works and merged the first 2 elements, benefiting from the fact that $$$u$$$&$$$x=0$$$.

1000F - One Occurrence

Let $$$sq$$$ denote $$$\lceil\sqrt{n}\rceil$$$.

A solution using DFS trees

If you're not familiar with back-edges, I recommend reading this first.

Let's take the DFS tree of our graph. Assume you're currently in node $$$u$$$ in the DFS. If $$$u$$$ has $$$sq-1$$$ or more back-edges, look at the one that connects $$$u$$$ to its furthest ancestor. It forms a cycle of length at least $$$sq$$$. If $$$u$$$ doesn't have that many back-edges, you can add it to the independent set (if none of its neighbors was added.) That way, if you don't find a cycle, every node only blocks at most $$$sq-1$$$ other nodes, the ones connected to it by a back-edge, so you'll find an independent set!

A solution using degrees

There's a pretty obvious greedy algorithm for finding large independent sets: take the node with the minimal degree, add it to the independent set, remove it and all its neighbors from the graph, and repeat. If at every step the node with the minimal degree has degree $$$\le$$$ $$$sq-1$$$, that algorithm solves the first problem. Otherwise, there's a step where EVERY node has degree at least $$$sq-1$$$. For graphs where every node has degree at least $$$d$$$, you can always find a cycle with length $$$d+1$$$: take an arbitrary node as a starting point, and keep trying to extend your path. If one of this nodes' neighbors is not already in the path, extend that path with it. Otherwise, all your $$$d$$$ neighbors are on the path. Take the edge to the furthest and you'll form a cycle of length at least $$$d+1$$$!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English mohammedehab2002 2020-03-29 19:17:48 7 Tiny change: 's degree $\le$ $sq-1$, tha' -> 's degree $<sq-1$, tha'
en6 English mohammedehab2002 2020-03-14 20:39:32 266
en5 English mohammedehab2002 2020-03-14 19:40:33 0 (published)
en4 English mohammedehab2002 2020-03-14 19:40:05 344 Tiny change: 'problem:1000A]\n\n$a=1' -> 'problem:1035A]\n\n$a=1'
en3 English mohammedehab2002 2020-03-14 04:22:11 696 Tiny change: '[problem:1000A]\n\n$a=1' -> '[problem:1135A]\n\n$a=1'
en2 English mohammedehab2002 2020-03-11 00:16:49 1583 Tiny change: 'he answer is at most $2\sqrt{M' -> 'he answer can't exceed $2\sqrt{M'
en1 English mohammedehab2002 2020-02-25 06:43:11 3745 Initial revision (saved to drafts)