Hello! I'm happy to announce XXI Open Cup. Grand Prix of Korea.
- Contest link: https://official.contest.yandex.ru/opencupXXI/contest/20794/enter
- Contest time: 2020/10/11 Sunday, 17:00 Korea Standard Time (UTC+9). For external accounts, the contest is ready now.
- Division 1 Problemsetters: ainta, jh05013, kdh9949, ko_osaga, TLEwpdus.
- Division 2 Problemsetters: Diuven, etaehyun4, jh05013, jihoon, kdh9949, ko_osaga
- Codeforces Gym: Division 1 Division 2
Special thanks to xiaowuc1 for revising our English.
List of relevant previous contests:
- XVIII Open Cup. GP of Korea
- KAIST RUN Spring Contest 2018
- XIX Open Cup. GP of Korea
- XIX Open Cup. GP of Daejeon
- XX Open Cup. GP of Korea
Enjoy!
What will be level of problems ,is it recommended for Div 2 participants?
The problemset is designed for teams preparing ICPC Semifinals or World Finals.
Will there be a Div2 OpenCup contest?
I sent it to Snark, but apparantly he didn't processed it. Div2 counterpart (KAIST 10th ICPC Mock Contest) will be uploaded to Gym shortly after.
You mean shortly after the Div 1 starts today, or in a few days?
I hope the former unless sth is broken.
I can't guarantee, so if you want team participation, it's better to schedule later.
Thanks!
Is there Div 2 editorial?
I: Subtract version. Only master is to calculate subtree sum quickly.
How to solve F?
Interval graph is acyclic if there are at most 2 intervals at each point. If this is true then you can divide these alive intervals into two sets of nonoverlapping intervals. Hence you can solve this using maxflow mincost, where flow has value 2 and there are edges $$$i \to i+1$$$ with capacity $$$2$$$ and cost $$$0$$$ and $$$s \to e+1$$$ with capacity $$$1$$$ and cost $$$-w$$$ for each interval. To speed things up you need to compute potentials with dynamic programming instead of Bellman-Ford/SPFA and you can do this since this graph is acyclic.
Apparently you don't need to compute potentials quickly, we passed pretty comfortably with book SPFA.
EDIT For reference, we just used https://github.com/ecnerwala/cp-book/blob/40b6ce3f17a5b917531b44404fbc7d9e0d1e4cd7/src/mcmf.hpp, which is based on https://github.com/kth-competitive-programming/kactl/blob/3e39f71e55fb414540d518b11dc40216fe22fe1a/content/graph/MinCostMaxFlow.h but supports sparse graphs.
We didn't :(
I would say that your implementation is quite far from book SPFA, for me it's unintuitive that abusing priority queues in such a way is even possible :)
We tested all kinds of SPFA listed in Wikipedia, and any of them couldn't pass our data in <15s, which was in turn 100% random.
Also, I'm convinced that yours could provably run in $$$O((n + m) \log n)$$$ time given that the underlying graph is DAG.
Doesn't this shortest path algorithm works exponentially long on test like
and so on?
I'm not sure if tests like this are constructible in min-cost-like problems, but seems to be strange. Anyway, it would probably be very fast on average.
I haven't looked in a while, but I thought it is upper bounded by O(VE). It might not be though...
See subtasks 4 and 6 of https://tlx.toki.id/problems/apio-2013/C/
Ah, I remember how it works. In SSPA, if all edges are initially positive cost, then we maintain a potential function which ensures they stay positive, so the runtime is just Dijkstra. If the edge costs can be initially negative, you should run a first pass of Bellman Ford to initialize the potential function (which I seem to be missing, but KACTL has).
Our implementation adjusted the edge costs to implicitly choose a potential function of -x*10**12, just like Petr suggested.
If all edges are initially positive, it's okey. I thought you are claiming your code to work with negative edges too, and was a bit surprised.
We just set the initial potentials to -x*10**12, no need for dynamic programming :)
Thank you for your participation!
How to A properly? Our solution is:
For two vectors
a
andb
the maximal number of things we can present is max flow of the complete bipartite graph with unit edges between the sides, and with edges from source to left with capacities $$$a_i$$$ and from right to sink with capacities $$$b_i$$$. Or, equivalently, min cut. If we take $$$k$$$ vertices from the left side into the mincut and $$$m - l$$$ vertices from the right side, then we need to check if the sum of maximal $$$k$$$ $$$a_i$$$-s plus sum of maximal $$$(b_j - k)$$$-s minus sum of all $$$b$$$-s can be greater than zero, or something. This is a segment tree with+=
on subseg andgetmax
on the whole tree. Did 46 teams implement the exact this? I think it's quite tricky to avoid mistakes here.I implemented that. It's not mandatory to interpret such as maxflow, but I don't know any other solution that has a different implementation.
Our interpretation was something similar to the Erdos-Gallai theorem so the implementation wasn't as tricky, but we had a lot of failed submissions because of other reasons xD
Quite standard problem and approach I would say. Moreover you can copy and paste this segment tree to E and L!
Yea, today I've used the same segment tree in 3 problems xd
This problem is almost the same as the bipartite graph realization problem. Our team googled and found out the Gale–Ryser theorem. It's not hard to prove that after changing the condition of $$$\sum\limits_{i=1}^n a_i = \sum\limits_{i=1}^n b_i$$$ to $$$\sum\limits_{i=1}^n a_i \leq \sum\limits_{i=1}^m b_i$$$, the theorem works for this problem. The remaining part is just using a segment tree to keep track of the inequalities.
Where to find problems?
How could one upsolve div2 contest ?
E was nice, but almost identical to this problem: https://codeforces.net/contest/1109/problem/F
I even have a TLE attempt on this problem, what a shame. Sorry!
Actually, the problem had an underlying graph as a tree, but we have changed it after I remembered a problem in Ptz which was exactly the same. Though, the model solution was a complicated $$$O(n \log^2 n)$$$ one, and my solution was n^2.
I love this set, thanks!
Our solution in E was in $$$O(n\log{n})$$$ time, yet no link-cut or other fancy structures were required; the main part of our solution was to find such $$$r$$$ for each $$$l$$$ that the induced subgraph on vertices $$$[l, r]$$$ is a set of isolated paths and vertices; this is done by maintaining the paths as a set of treaps (each path is an in-order traversal of some treap) and then moving two pointers, after this some segment tree.
300iq provided a fix to my idea. So we can use the Queue Undo Trick for this idea, by imagining that we insert and pop vertices, as here inserting vertices is $$$O(1)$$$ updates to dsu, but we cannot use this to replace the LCT in editorial.
The contest is ready in Codeforces Gym. Enjoy!
A set of interval covers each point at most K times if and only if it can be partitioned into K disjoint set of intervals. You can prove this by greedy algorithm or using the fact that interval graphs are perfect.
What does perfect mean in the editorial?
This can directly proved by Dilworth theorem
As in perfect graph.