### 300iq's blog

By 300iq, 9 months ago, ,

Hello everyone, this summer at Petrozavodsk was my second ICPC contest, now it will be held as OpenCup round.

XX Open Cup Grand Prix of Kazan takes place on Sunday, September 8, 2019, at 11:00 AM Moscow time

The link to the contest. You need an Open Cup login to participate.

To ensure Codeforces traditions, I will say thanks to the testers Benq, wxhtxdy, whzzt, sunset, TLE, ko_osaga, rushcheyo, jiry_2, gamegame, CauchySheep. Also thanks to izban with help in tasks choosing.

UPD: Now the contest is loaded to the gym!

• +273

 » 9 months ago, # |   +31 The contest will start in less than 30 minutes!~
 » 9 months ago, # |   +74 Thanks, everyone, for participating! Editorial pdf: link
•  » » 9 months ago, # ^ |   +30 Can you give the pdf link of problems, its hard to login.
 » 9 months ago, # |   +41 Hello! I was the tester, and I really liked problem H here. It is easily my best problem of 2019. Please solve it!
•  » » 9 months ago, # ^ |   +69 (^з^)-☆ ♥ ♥ ♥ ♥ ♥ ♥
 » 9 months ago, # |   +38 My D passed a stress test but failed on test 9. Do anyone have any idea for the reason?
•  » » 9 months ago, # ^ | ← Rev. 2 →   +28 10 11 3 1 2 1 3 1 8 1 9 3 4 3 5 4 5 6 7 6 8 7 8 9 10 Answer is 4.
•  » » » 9 months ago, # ^ |   +41 Finally I found a stupid bug and ACed. Thank you for the nice problem set:)
•  » » 9 months ago, # ^ | ← Rev. 2 →   0 On the other hand, we got AC on problem A which failed our stresstests 8) (not sure if it satisfied input constraints but we were treating input just as a chordal graph of treewidth <=3) But we managed to find the but afterwards
•  » » » 9 months ago, # ^ |   0 Maybe your algorithm of recognition is not correct for arbitary chordal graph with small treewidth?
•  » » » » 9 months ago, # ^ |   0 That part was trivial. Just find a vertex whose neighbourhood is a clique and remove it . Moreover, naive way of recognition gives you n^2 time, but you can do it with lexbfs in linear or n log n time (I don't remember), what gives a much better complexity than what was written in editorial, since the latter dp part is linear. But anyway, that linear dp part has constant factor sth like 100000, so yeah xD. Our bug was in processing the Join nodes, but it was very hard to find a test where it fails (it was once per a few thousands in our stresstests), so I am not surprised we managed to pass system tests. We didn't think if it is possible to find a failing tests that is compliant with problem constraints, but this should be possible.
•  » » » » » 9 months ago, # ^ |   0 Well, if with arbitary chordal graph you found it with several thousand iterations, probably Apollonian network will require much more iterations :)So it was hard for me to predict your bug :(Anyway, hope you liked this problem xd
•  » » » » » » 9 months ago, # ^ |   +10 I was the one to read it and state "well, it's rather obvious — just standard connectivity dp over bounded treewidth" and delegated coding it to Marek xD. So well, let's say that coding these is kind of a masochistic pleasure, like geometry which I forced myself to enjoy xD. And we can brag afterwards that we actually coded on a competition something that nobody sane ever attempts to code xD.
•  » » » » » » » 9 months ago, # ^ |   0 Real masochistic pleasure comes from the first solution of J. I spent slightly more than a full day to solve it in that way. Everybody should upsolve J in that way XD
•  » » » » » » » » 9 months ago, # ^ |   +20 For even more 'pleasure', solve it in basically the same way, but with a LinkCutTree instead of HLD (which I just did).
•  » » » 6 months ago, # ^ | ← Rev. 2 →   0 Sorry for necroposting, but could you please share how you wrote the generator for chordal graphs with bounded treewidth?
•  » » » » 6 months ago, # ^ |   +13 I am not sure that's the exact way we used during contest, but what I would do right now is to start with a triangle and repeatedly find random 3 vertices that form a triangle and create a new vertex and connect it to all vertices of that triangle (since it needed to have tw<=3).
•  » » » » » 6 months ago, # ^ |   0 Thanks!
 » 9 months ago, # |   +103 I also love the problems, especially F, H and J. One of the best rounds ;)
•  » » 9 months ago, # ^ |   +20 I really liked F and especially H as well!
 » 9 months ago, # |   +18 In K, isn't there $K^2$ possible candidates? Doing Inclusion-Exclusion over that many elements is too much right?
•  » » 9 months ago, # ^ |   0 Yeah, there are around $70$ possible candidates. But with described optimizations solution works much faster than $2^{70}$.
 » 9 months ago, # |   +16 How can I get an Open Cup login QwQ
•  » » 9 months ago, # ^ |   +3 Contact snarknews~
 » 9 months ago, # |   +20 I think the first step of A can be done by removing 3-degree vertex repeatedly.
•  » » 9 months ago, # ^ |   +40 Well, if you will delete arbitrary vertex of degree 3 it won't work, because at some moment you can delete some border vertex of the triangle, and there may be no possible variant to continue this decomposition :)
•  » » 9 months ago, # ^ |   +20 Depends on what kind of decomposition you're aiming for. We deleted vertices with degree 3 whose neighbourhood is a clique, but we can get some different decomposition than one described in statement (because of what ~300iq said), but it didn't matter to us at all. Maybe it is important to some other solutions.
•  » » » 9 months ago, # ^ | ← Rev. 3 →   +20 Yes, it was not correct way for "Apollonian Network". However it works when we ignore planarity and we can obtain a tree decomposition of tree-width -4- 3 in O(N). Then we must be able to construct O(N) DP.
•  » » » » 9 months ago, # ^ |   +30 Exactly, that's what we did during contest :)
•  » » » » 9 months ago, # ^ |   0 What's "tree decomposition of tree width 4"?
•  » » » » » 9 months ago, # ^ |   +10 For Apollonian Network you can build tree decomposition with treewidth 4
•  » » » » » » 9 months ago, # ^ |   +40 To be precise, bags are of size <=4, so the treewidth is <=3 xD
•  » » » » » » » 9 months ago, # ^ |   0 For dp part, what are the states for each bag (k4)? I feel there are too many (like if the corners are used, if the edges are used). But then merging three such states to get the parents state is yet another nightmare. Any simpler way to think about it?
•  » » » » » » » » 9 months ago, # ^ | ← Rev. 2 →   0 Actually you don't need info about edges, just maintain connected components of its vertices and their degrees :)Key idea is that in fact you can look at path like a "connected set of vertices with degrees <= 2 and exactly two vertices with degree = 1".
 » 9 months ago, # |   +9 300iq Can you share the problem set here as pdf or something for ppl without Open cup logins please :)
•  » » 9 months ago, # ^ |   +29 Soon I will load the contest to codeforces gym, don't worry.
 » 9 months ago, # |   +30 It's funny that problems H and J were kinda similar and during competition I thought that H will be solved by augmenting paths and J will be solved by parametric search but it turned out to be exactly opposite xD
•  » » 9 months ago, # ^ |   0 XD, for me it looks impossible to use augmenting paths, when you have queries on segments? :P
•  » » » 9 months ago, # ^ |   0 That's why I had no idea how to solve it xD. By the way, augmenting paths looked impossible in J as well, I have to admit that none of us understands anything from that solution even now :(
•  » » » » 9 months ago, # ^ |   +8 Oh, that is sad, I thought that this solution should be simple to come up with but impossible to write :)
•  » » » » 9 months ago, # ^ |   -28 I already told you swistakk, as the age passes you are not as clever as you were in your young days, so don't repent if any problem is not solved.
 » 9 months ago, # |   +13 In problem E how to do Gaussian Elimination in $O\left(\frac{(n+60)^2}{64}\right)$ per every new vector?
•  » » 9 months ago, # ^ | ← Rev. 3 →   +20 Store the basis in form $base[i]$ — the vector of the maximum price which has its first bit set at $i$ or None. When adding, iterate over the set bits $i$ of the new vector. As usual, if $base[i]$ is None, put it there and break. If the price of $base[i]$ is lower than the new one, swap your vector with $base[i]$ and continue as if the new vector was in the basis and you were adding $base[i]$ to it.
 » 9 months ago, # |   +28 Could someone please shed some more light on problem C? I don't really get the idea from the editorial.
•  » » 3 months ago, # ^ | ← Rev. 5 →   +18 Let's do three DPs:$f(u, S):$ Number of cactuses rooted at $u$, and the nodes in set $S$ are available.$g(u, S):$ Same as $f$, but $u$ can create at-most $1$ sub-tree. That is, number of cactuses rooted at $u$ on nodes from $S$, such that $u$ is attached to only one other node or part of only one cycle.$h(u, v, S):$ Number of cactuses rooted at $v$ with nodes from $S$, that loops back to $u$. (Assuming there is already a path from $v$ to $u$, this dp should create a path from $u$ to $v$, including the possibility of $u\to v$.) Transitions for f(u, S)This is the easiest one.Take any $T \subseteq S$, create a sub-tree cactus with nodes in $T$ using $g(u, T)$ and another cactus with nodes in $S\setminus T$ using $f(u, S\setminus T)$. To avoid double counting, you should use some kind of ordering when choosing the subset $T$. For example: always include the node with maximum id in $T$. Transitions for g(u, S)This is the hardest one to get rid of over-counting.Consider each node $v \in S$ adjacent to $u$. You have two options after adding the edge $(u, v)$: Create separate cactus on $v$, with $f(v, S\setminus v)$. Create a cactus on $v$ and loop back to $u$, with $h(v, u, S\setminus v)$. After this you'll need to divide the answer by $2$. Why? There are no over-counting in choice 1. But in choice 2, you may count cycles like $uvwu$ and $uwvu$ twice.Additionally, $H$ may count $uvu$ as a cycle and proceed to build another cactus on $u$ with remaining nodes. But that breaks the condition of $G$ that $u$ creates only one subtree. However, note that the sum of the counts where $uvu$ cycle is considered is same as the sum of counts of choice 1. So dividing the answer by $2$ will fix both over-counting problems. Transitions for h(u, v, S)For each node $w$ adjacent to $u$, consider all $T\subseteq S$ with $w \in T$ and create a cactus on $u$ with nodes in $S\setminus T$ via $f(u, S\setminus T)$ and continue building the cycle with rest of the nodes via $h(w, v, T\setminus w)$. However if $w = v$, then you should complete the cycle and continue building another cactus on $u$ via $f(u, S)$.
 » 9 months ago, # |   +3 Can anyone give me 8th test of the problem D, I can't find my bug :(
•  » » 9 months ago, # ^ |   +8 You may write stress-test, it is not very hard in this problem.
•  » » » 9 months ago, # ^ | ← Rev. 2 →   0 I wrote stress-test and found my mistake after my comment :) Thanks anyway!