Note: on BZOJ this one is a members-only problem; I did it on JZOJ.
Having just solved the power network problem, Ali is stumped once again by a task from the leadership.
As mentioned before, Ali's country has \(n\) cities. Now the country needs to build some trade routes between certain pairs of cities, so that any two cities in the whole country are connected, directly or indirectly.
Continue reading →Chinese original · English translation by Claude Opus 5.5
In informatics competitions, polynomial multiplication shows up very, very often. The naive algorithm has time complexity \(O(n^2)\), which has made it the place where many nasty problem setters fail solutions on the exponent. So it is very necessary to use the Fast Fourier Transform (FFT) to optimize polynomial multiplication. Next, going from the shallow to the deep, I will introduce these two and the relationship between them.
Continue reading →Chinese original · English translation by Claude Opus 5.5
Actually, I should have been able to solve this one during the contest; it's a very simple counting problem. In the exam room, the moment I saw strings I froze. For some reason I'm traumatized by lexicographic order on strings, but looking at it now, it's just an idiotic problem.
Continue reading →Chinese original · English translation by Claude Opus 5.5
This problem really is a free-points problem (I was just about to come up with straight brute-force enumeration + DSU when I went and looked at the solution, and in the end it turned out to be exactly this stupid).
Consider enumerating the frequency interval \([L, R]\) (sort the edges, fix the lower bound and then enumerate the upper bound); this part is \(O(m^2)\). Every time we enumerate a lower bound we have to initialize the DSU, and then when merging two sets we just update the answer according to their sizes.
Continue reading →Chinese original · English translation by Claude Opus 5.5
In a directed graph, there is a unique source (in-degree 0) and sink (out-degree 0), every edge has a non-negative capacity, and the whole graph is guaranteed to stay in a balanced state. Such a graph is called a network flow graph.
The most liquid flowing through each pipe every second. The commonly used algorithm is Dinic. First run a BFS to divide the graph into levels, then use DFS to push the flow. Dinic's algorithm makes use of the residual network on the network graph to obtain the maximum flow.
Continue reading →Chinese original · English translation by Claude Opus 5.5
In the contest I coded up a wrong solution for this problem, and still scraped 30 points with it.
The normal line of thinking is: find a few edges on the shortest path graph and modify them. However, the optimal solution doesn't necessarily lie on edges of the shortest path graph; it can also be reached by modifying suboptimal edges. So this problem actually doesn't have all that much to do with shortest paths, even though Djisktra will be used later to compute shortest paths.
Continue reading →Chinese original · English translation by Claude Opus 5.5
I haven't written this one yet. It's a digit DP; memoized search is recommended.
This is a really good problem.
First, for the case \(m = n - 1\), that is, when it is a tree, we can consider pushing from the bottom up, i.e. starting from the leaf nodes; see how Toposort is written in the code. Then, for the case \(m > n\), we can just output \(0\), because this system of equations has no unique solution: \(m\) unknowns with only \(n\) conditions, which does not work.
Continue reading →Chinese original · English translation by Claude Opus 5.5