SorahISA's blog

By SorahISA, 2 months ago, In English

This blog post is a submission for the Codeforces Month of Blog Posts Pt. III challenge. Thank you cadmiumky for the initiative!

Introduction Problem

ICPC North America Championship 2025, Problem B - Circle of Leaf

Before tackling the problem, let's first try some simple examples.

The notation we use will also be introduced in the examples, so please try to understand them carefully.

Example 1
Example 2
Example 3
Example 4

Enough examples, let's try to solve the problem now.

Solution

Implementation

Code: https://qoj.ac/submission/2028368

Depends on problem requirement, the Info struct and the three operations Prune, Twist and Compress may be defined differently. Basically, the Info struct should store the information of a cluster, and the three operations should be defined according to the meaning of the information stored in the Info struct.

Code (Structure Definition and Operations)

For simplicity, we will use vector<map<int, Info>> to store the adjacency lists and the info on the edge to represent the graph, and use two queues to maintain the nodes with degree $$$1$$$ or $$$2$$$.

Here is the pseudo code of the reduction process:

Pseudo Code (Reduction Process)

Generalization

General Series-Parallel Graphs (GSPG)

If a graph can be constructed by repeatedly applying the following operations starting from a single node, then it is called a General Series-Parallel Graph.

  1. Add a new isolated node.
  2. Add a new node with an edge connecting it to any existing node.
    • It is the inverse operation of prune.
  3. Duplicate any existing edge by adding a new edge between the same pair of nodes.
    • It is the inverse operation of twist.
  4. Subdivide any existing edge by adding a new node in the middle of the edge.
    • It is the inverse operation of compress.
Random Facts

Trees are GSPG, cactuses are GSPG, outer planar graphs are GSPG!

If a graph is a GSPG, then we can apply the reduction process to it until there is only one node left.

Connected Graphs with Small $$$m - n$$$

Observe the operations:

  • in Prune operation, $$$n \gets n - 1$$$ and $$$m \gets m - 1$$$;
  • in Twist operation, $$$n \gets n$$$ and $$$m \gets m - 1$$$;
  • in Compress operation, $$$n \gets n - 1$$$ and $$$m \gets m - 1$$$.

The value of $$$m - n$$$ will never increase and will decrease by $$$1$$$ per Twist operations.

When the reduction process stops, we have the degree of each node at least $$$3$$$, so we can yield $$$2m' \ge 3n'$$$.

Suppose $$$m - n \le k$$$ in the original graph, then we have $$$m' - n' \le k$$$ and $$$2m' \ge 3n'$$$, which yields $$$n' \le 2k$$$ and $$$m' \le 3k$$$.

Thus, if $$$m - n$$$ is small, we can apply the reduction process until there are at most $$$2k$$$ nodes and $$$3k$$$ edges left, and then solve the problem by brute force.

Values on Boundary Nodes

Sometimes, we may want to maintain some values on the boundary nodes of the cluster, and the operations should also update these values together with the information on the edge.

Practice

If you know some problem that can be solved by the method, please share it in the comments.

(I will try to put some problems on polygon when I have time...)

Library Checker - Tree Decomposition (Width 2)
DAG Counting (No Link)
Mutual Tests 2019, Round 3, Problem C - Park
YTP 2025 Senior, Problem 19 - Polygon Triangulation

Notes: There are subtasks to test the solution without modifications.

References

  1. https://github.com/enkerewpo/OI-Public-Library/blob/master/IOI%E4%B8%AD%E5%9B%BD%E5%9B%BD%E5%AE%B6%E5%80%99%E9%80%89%E9%98%9F%E8%AE%BA%E6%96%87/%E5%9B%BD%E5%AE%B6%E9%9B%86%E8%AE%AD%E9%98%9F2019%E8%AE%BA%E6%96%87%E9%9B%86.pdf, page 165-191 (Chinese)
  2. https://zhuanlan.zhihu.com/p/32413108 (Chinese)
  3. https://oi-wiki.org/ds/top-tree/ (Chinese)
  4. https://en.wikipedia.org/wiki/Series%E2%80%93parallel_graph

Full text and comments »

  • Vote: I like it
  • +80
  • Vote: I do not like it

By SorahISA, history, 3 years ago, In English

Recently, I virtually participated in several gym contests, but when I want to look up my participation, all I can see is the last ten contests in "Recent virt. contests". The filter in the gym only has "Hide, if participated" instead of "Only show participated."

Also, I was invited to several custom mashup contests during the past few years. For those I had submissions, I can find the contest using the submission page (still time-consuming), but some of those with zero submissions are just gone.

Is there any way to find those dust-laden contests without manually checking each submission? If there isn't a way, I suggest adding virtual and gym contest results on the personal contest page and adding invited mashups to the personal mashup page.

Full text and comments »

  • Vote: I like it
  • +39
  • Vote: I do not like it

By SorahISA, history, 4 years ago, In English

As in the title, I came across this option when messing around with polygon and can not find any document.

This option is accessible from General info => Advanced => Scorer file.

It seems to be able to control the score for submission by printing a floating number.

Does writing custom scorer files allow us to make partial-scoring problem subtask-min-able? Or scoring function based on submission time like Div.1,2 rounds?

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it

By SorahISA, 7 years ago, In English
  • Vote: I like it
  • -56
  • Vote: I do not like it