CF - Wizard's Tour

Author: Benjamin Qi

Table of Contents

Tree CaseGeneral Case

Official Editorial (brief)

In other words, we want to pair up as many edges as possible such that the edges in each pair share a vertex.

Obviously the task can be solved independently for each component.

The answer is always m2\left\lfloor \frac{m}{2}\right\rfloor for a single connected component.

Tree Case

Solution

General Case

Solution

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!